php5.3.3 编译安装到lighttpd中注意事项
系统环境:
# cat /etc/redhat-release
CentOS release 5.4 (Final)
# ./lighttpd -v
lighttpd/1.4.28 - a light and fast webserver
Build-Date: Nov 1 2010 07:57:36
要安装的php版本
#./php-cgi -v
PHP 5.3.3 (cgi-fcgi) (built: Nov 3 2010 00:57:24)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
php5.3.3和以前的版本编译安装有很多不同,开始搜索文章是按php5.2.x版本操作结果不对,且很多文章人云亦云。
php的常用功能基本都有了,一般正式服务器
所有软件的配置文件都放到一起。
再就是下载后的源码,编译完了最好别删除。
所有网站都会放到单独一个目录例如/home/web/目录而不是啥 /var/www。
第一步:
先说下php的运行原理为啥lighttpd能解析php(当然高手略过)
举个例子你在浏览器里输入http://www.a.com/index.php会一次经过以下步骤
a.浏览器发送请求到www.a.com的服务器的80号端口,而lighttpd监控80号端口,所以他会处理这个
b.lighttpd接到这个请求后一看是.php,结尾就会找能解析php的 模块 (cgi)来解析这个文件(简单理解就是会找个程序来解析.php里边的指令)
c. 请看lighttpd中针对php的配置lighttpd/conf.d/fastcgi.conf
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/local/php-5.3.3/bin/php-cgi",
"socket" => "/tmp/php-fastcgi-1.socket",
)))
d.所以.php 的文件就会用/usr/local/php-5.3.3/bin/php-cgi 来解析,然后把结果返回给lighttpd-> 浏览器
第二步:
下边说编译安装时注意的地方
1.不再需要enable-fastcgi,php5.3中强制启用了fastcgi
若加上此参数最后会提示没有此参数
2.mysqlnd,这个php5.3中自己带了个,介绍说性能比以前好很多,所以编译时的--with-mysqli=/usr/bin/mysql_config 应改成如下这样
--with-mysqli=mysqlnd --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd
具体指令如下:
./configure --prefix=/usr/local/php-5.3.3 --disable-debug --with-config-file-path=/usr/local/php/conf --enable-shmop --with-gd --with-jpeg-dir --with-png-dir --with-libxml-dir --with-zlib-dir --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --enable-sockets --with-iconv=/usr/local/libiconv-1.12 --enable-mbstring --enable-mbregex --enable-ftp --enable-gd-native-ttf --with-freetype-dir=/usr/local/freetype-2.3.7
之前请先编译安装freetype-2.3.7,libiconv-1.12
参数解释如下
--prefix php 安装位置
--with-config-file-path 自定义配置文件路径,例如/home/server/php
--enable-shmop 打开对内存操作相关函数的支持,具体搜索php手册shmop_open函数或google之
--with-gd 打开gd库支持,否则验证码啥的就不能用了
--with-jpeg-dir --with-png-dir 对jpeg和png的支持
--with-libxml-dir 对xml操作的支持,必须得有,缺少库自己rpm或source个安装
--with-zlib-dir 对文件压缩输出的支持
--with-mysqli=mysqlnd --with-mysql=mysqlnd mysql驱动 mysqlnd在php5.3成了php的一部分不在需要加载mysql自带的驱动
--with-pdo-mysql=mysqlnd pdo访问数据库方式的支持
--enable-sockets 对socket相关函数的支持对应php手册Socket Functions章节
--with-iconv 对编码转化的支持
--enable-mbstring --enable-mbregex 对多字节语言支持对应php手册Multibyte String Functions章节
--enable-ftp 对ftp函数的支持
用途之一:资讯网站为了网站安全,整个网站任何目录都不加写入权限。只允许读,所有生成的静态文件或上传图片先放到临时目录tmp然后
通过ftp函数传到网站根目录下
--enable-gd-native-ttf --with-freetype-dir 对中文字体和常用字体的支持
用途:一般生成图片牵扯到中文时会用
3.编译若碰到缺少库一个个对着安装就行,有时候rpm -qa查找到已经安装了,有可能是版本太低,卸载掉,重新装个新版本
4.编译安装完后,修改lighttpd/modules.conf文件
去掉 include "conf.d/fastcgi.conf"前的#号
5.修改fastcig.conf 文件增加如下几行
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/local/php-5.3.3/bin/php-cgi", #这行即你安装php后再bin目录下解析php的那个程序的位置
"socket" => "/tmp/php-fastcgi-1.socket", #这是文件会自动创建不用理它,但的保证tmp目录可写
)))
备注:
#wget http://mirror.bjtu.edu.cn/gnu/libiconv/libiconv-1.12.tar.gz
#tar zxvf libiconv-1.12.tar.gz
#wget http://sourceforge.net/projects/freetype/files/freetype2/2.3.7/freetype-2.3.7.tar.gz/download
#tar zxvf freetype-2.3.7.tar.gz #配置时出错,就make clean再configure一次
php5.3.3新特性参考这篇文章:http://willko.iteye.com/blog/348982