#./configure\
--prefix=/usr/local/php\
--enable-fastcgi\
--enable-fpm (配置php-fpm,指定--prefix,若不指定,默认的目录为/usr/local,编译后显得比较零乱.)#makeall (编译所有)
#makeinstall (编译安装,完成安装)检查安装
#cd/usr/local/php/bin
#./php-v (显示如下内容,表示安装正常)
PHP5.2.8(cli)(built:
Aug11200922:
53:
04)
Copyright(c)1997-2008ThePHPGroup
ZendEnginev2.2.0,Copyright(c)1998-2008ZendTechnologies将php-5.2.8目录下的php.ini-dist复制到/usr/local/php/lib/php.ini修改/usr/local/php/etc/php-fpm.conf配置文件
去掉user,group两行的注释
Unixuserofprocesses
nobody
Unixgroupofprocesses
nobody启动php-fpm
#/usr/local/php/sbin/php-fpmstart2.nginx的安装
#gunzipnginx-0.8.8.tar.gz|tarxvf-(解压缩包nginx-0.8.8,生成目录nginx-0.8.8)
#cdnginx-0.8.8
#./configure\
--prefix=/usr/local/nginx (指定--prefix.配置前,需要先安装pcre-devel)#make (编译)
#makeinstall (编译安装)配置nginx
修改/usr/local/nginx/conf/nginx.conf配置文件,需做如下修改
usernobodynobody; (首行user去掉注释,并与php-fpm.conf中的user,group配置同) server{
listen 8080; (修改所使用的端口)
server_namelocalhost;(修改所使用的服务器名)#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:
9000location~\.php${
root html;
fastcgi_pass 127.0.0.1:
9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; (取消FastCGIserver部分location的注释,并要注意fastcgi_param行的参数,$fastcgi_script_name应改为$document_root$fastcgi_script_name,或者使用绝对路径)完成配置后启动
#/usr/local/nginx/sbin/nginx编写个phpinfo.php文件保存在/usr/local/nginx/html/目录下,文件内容如下
phpphpinfo();?
>
php-fpm不用再依赖其它的fastcgi启动器,比如lighttpd的spawn-fcgi。
php-fpm的使用非常方便,配置都是在php-fpm.ini的文件内而启动,重启都可以从php/sbin/php-fpm中进行更方便的是修改php.ini后可以直接使用php-fpmreload进行加载无需杀掉进程就可以完成php.ini的修改加载结果显示使用php-fpm可以使php有不小的性能提升php-fpm控制的进程.cpu回收的速度比较慢.内存分配的很均匀而spawn-cgi控制的进程CPU下降的很快.而内存分配的比较不均匀.有很多进程似乎未分配到,而另外一些却占用很高.可能是由于进程任务分配的不均匀导致的.而这也导致了总体响应速度的下降而php-fpm合理的分配.导致总体响应的提到以及任务的平均
使用php-fpm需要在php源码上打补丁,然后重新编译php
一.下载php-fpmwgetwgethttp:
//php-fpm.anight.org/downloads/head/php-5.2.8-fpm-0.5.10.diff.gz
与php-5.2.9在同一级目录gzip-cdphp-5.2.8-fpm-0.5.10.diff.gz|patch-dphp-5.2.9-p1
补丁打好以后,编译php的时候增加了下面几个参数:
–enable-fpm激活fastcgi模式的fpm支持–with-fpm-confphp-fpm的配置文件(默认是PREFIX/etc/php-fpm.conf)–with-fpm-logphp-fpm的日志文件(默认是PREFIX/logs/php-fpm.log)–with-fpm-pidphp-fpm的pid文件(默认是PREFIX/logs/php-fpm.pid)
./configure--prefix=/EBS/php\--with-config-file-path=/EBS/php/etc\--enable-fastcgi\--enable-fpm\--OTHERS注:
--enable-fastcgi\需要在--enable-fpm\的前面,否则,fpm不能编译上。
详细的lamp部署,查看二.编译好php后,修改配置文件vi/EBS/php/etc/php-fpm.conf需要注意下面几处配置
127.0.0.1:
9000这个表示php的fastcgi进程监听的ip地址以及端口
nobodynobody表示php的fastcgi进程以什么用户以及用户组来运行,默认该行是注释掉的,需要打开
0是否显示php错误信息
5最大的子进程数目运行php-fpm:
php-fpm用一个程序来控制fastcgi进程,这个文件在$PREFIX/sbin/php-fpm/usr/local/php/sbin/php-fpm该程序有如下参数:
start启动php的fastcgi进程stop强制终止php的fastcgi进程quit平滑终止php的fastcgi进程restart重启php的fastcgi进程reload重新加载php的php.inilogrotate重新启用log文件也就是说,在修改了php.ini之后,我们可以使用/usr/local/php/sbin/php-fpmreload这样,就保持了在php的fastcgi进程持续运行的状态下,又重新加载了php.ini。
三、配置nginxuserwwwwww;worker_processes10;error_loglogs/error.lognotice;pidlogs/nginx.pid;#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.worker_rlimit_nofile51200;events{ useepoll; worker_connections51200;}http{ includemime.types; default_typeapplication/octet-stream; charsetgb2312; server_names_hash_bucket_size128; #sendfileon; #tcp_nopushon; keepalive_timeout60; tcp_nodelayon; gzipon; gzip_min_length1k; gzip_buffers48k; gzip_http_version1.1; gzip_typestext/plainapplication/x-javascripttext/csstext/htmlapplication/xml; server { listen80; server_name192.168.1.2; indexindex.htmlindex.htmindex.php; root/EBS/www; if(-d$request_filename) { rewrite^/(.*)([^/])$http:
//$host/$1$2/permanent; } location~.*\.php?
$ { includefcgi.conf
fastcgi_pass127.0.0.1:
9000; fastcgi_indexindex.php; } log_formataccess'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent"$http_x_forwarded_for'; access_loglogs/access.logaccess; }}
/usr/local/nginx/conf/fcgi.conf注:
nginx自带了一个配置文件,/usr/local/nginx/conf/fastcgi_params,该配置文件缺少粗体字体的部分,会造成访问php文件时报404错误。
fastcgi_paramGATEWAY_INTERFACECGI/1.1;fastcgi_paramSERVER_SOFTWAREnginx;fastcgi_paramQUERY_STRING$query_string;fastcgi_paramREQUEST_METHOD$request_method;fastcgi_paramCONTENT_TYPE$content_type;fastcgi_paramCONTENT_LENGTH$content_length;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;fastcgi_paramSCRIPT_NAME$fastcgi_script_name;fastcgi_paramREQUEST_URI$request_uri;fastcgi_paramDOCUMENT_URI$document_uri;fastcgi_paramDOCUMENT_ROOT$document_root;fastcgi_paramSERVER_PROTOCOL$server_protocol;fastcgi_paramREMOTE_ADDR$remote_addr;fastcgi_paramREMOTE_PORT$remote_port;fastcgi_paramSERVER_ADDR$server_addr;fastcgi_paramSERVER_PORT$server_port;fastcgi_paramSERVER_NAME$server_name;#PHPonly,requiredifPHPwasbuiltwith--enable-force-cgi-redirect#fastcgi_paramREDIRECT_STATUS200;
四配置XCache1、安装xcache模块wgettar-xvzfxcache-1.2.2.tar.gzcdxcache-1.2.2/usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/bin/php-config--enable-xcache--enable-xcache-optimizermakemakeinstall2、计算密码的md5值echo-n"password"|md5sum5f4dcc3b5aa765d61d8327deb882cf993、配置XCache;注:
zend_extension,用来加载zend的扩展,是绝对路径,extension是相对路径,相对于extension_dir的相对路径,非zend扩展如果你更改路径以后,一定要apachectlstop后再start,而不要restart。
vi/usr/local/php/etc/php.ini添加:
[xcache-common]zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so[xcache.admin];Changexcache.admin.usertoyourpreferredloginnamexcache.admin.user="admin";Changexcache.admin.passtotheMD5fingerprintofyourpassword;Usemd5-s"your_secret_password"tofindthefingerprintxcache.admin.pass="5f4dcc3b5aa765d61d8327deb882cf99"[xcache];Changexcache.sizetotunethesizeoftheopcodecachexcache.size=24Mxcache.shm_scheme="mmap"xcache.count=2xcache.slots=8Kxcache.ttl=0xcache.gc_interval=0;Changexcache.var_sizetoadjustthesizeofvariablecachexcache.var_size=8Mxcache.var_count=1xcache.var_slots=8Kxcache.var_ttl=0xcache.var_maxttl=0xcache.var_gc_interval=300xcache.test=Offxcache.readonly_protection=Onxcache.mmap_path="/tmp/xcache"xcache.coredump_directory=""xcache.cacher=Onxcache.stat=Onxcache.optimizer=Off[xcache.coverager]xcache.coverager=Onxcache.coveragedump_directory=""5、重启PHP模块正常load之后,在phpinfo显出的信息内Zend这快应该会加上XCache的内容
6、另外两种加速模块:
在我们的测试中,效果都要好于xcache,这3中加速不能同时存在两种,有冲突。
6.1apcwgetcdAPC-3.0.19/usr/local/php/bin/phpize./configure--enable-apc--enable-apc-mmap--with-apxs=/EBS/apache/bin/apxs--with-php-config=/EBS/php/bin/php-configmakemakeinstall6.2eacceleratorwgetcdeaccelerator-0.9.5.3/usr/local/php/bin/phpize./configure--enable-eaccelerator=shared--with-php-config=/EBS/php/bin/php-configmakemakeinstall
viphp.inizend_extension="/usr/local/php/lib