主要过程为:
一 编译安装php-5.3.10
二 整合nginx和php5
三 安装xcache,为php加速
一 编译安装php-5.3.10
首先下载源码包至本地目录,下载位置ftp://172.16.0.1/pub/Sources/new_lamp。(马哥教育的内部ftp)
# tar xf php-5.3.10.tar.bz2
# cd php-5.3.10 # ./configure –prefix=/usr/local/php –with-mysql=/usr/local/mysql –with-openssl –enable-fpm –enable-sockets –enable-sysvshm –with-mysqli=/usr/local/mysql/bin/mysql_config –enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib-dir –with-libxml-dir=/usr –enable-xml –with-mhash –with-mcrypt –with-config-file-path=/etc/php –with-config-file-scan-dir=/etc/php –with-bz2 –with-curl说明:如果前面第1步解决依赖关系时安装mcrypt相关的两个rpm包,此./configure命令还可以带上–with-mcrypt选项以让php支持mycrpt扩展。–with-snmp选项则用于实现php的SNMP扩展,但此功能要求提前安装net-snmp相关软件包。
# make
# make test # make intall为php提供配置文件:
# cp php.ini-production /etc/php/php.ini为php-fpm提供Sysv init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm # chmod +x /etc/rc.d/init.d/php-fpm # chkconfig –add php-fpm # chkconfig php-fpm on为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf 配置pm.的相关选项为你所需要的值,并启用pid文件(如下最后一行): pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 2 pm.max_spare_servers = 8 pid = /usr/local/php/var/run/php-fpm.pid接下来就可以启动php-fpm了:
# service php-fpm start使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm 二 整合nginx和php51、编辑/etc/nginx/nginx.conf,启用如下选项:
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; }2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name;并在所支持的主页面格式中添加php格式的主页,类似如下:
location / { root html; index index.php index.html index.htm; }而后重新载入nginx的配置文件:
# service nginx reload3、在/usr/html新建index.php的测试页面,测试php是否能正常工作:
# cat > /usr/html/index.php << EOF <?php phpinfo(); ?>接着就可以通过浏览器访问此测试页面了。
三、安装xcache,为php加速:1、安装
# tar xf xcache-1.3.2.tar.gz # cd xcache-1.3.2 # /usr/local/php/bin/phpize # ./configure –enable-xcache –with-php-config=/usr/local/php/bin/php-config # make && make install安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# cat xcache.ini >> /usr/local/php/lib/php.ini说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/usr/local/php/lib/php.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
3、重新启动php-fpm
# service php-fpm restart
补充说明
如果要在SSL中使用php,需要在php的location中添加此选项:
fastcgi_param HTTPS on;