nginx 下配置php-FPM

nginx 可以直接调用FPM来驱动php,从此就可以放弃apache了。什么原因不多说了。
先下载php5.4的安装包。

照别人的说法

./configure --enable-fastcgi --prefix=/data1/server/php-cgi --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-mysql --with-mysqli --with-pdo-mysql --enable-sockets --with-curl --with-ttf --with-libxml-dir --with-config-file-path=/data1/server/php-cgi/etc --with-zlib --enable-exif --enable-ftp --with-xmlrpc --enable-zip --with-iconv-dir --with-libxml-dir --with-mcrypt --with-tidy --with-tidy --enable-fpm --enable-force-cgi-redirect

提示无法安装enable-force-cgi-redirect 等等一堆玩意儿

好的,去掉一些东西来安装

./configure --prefix=/data1/server/php-cgi --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-mysql --with-mysqli --with-pdo-mysql --enable-sockets --with-curl --with-libxml-dir --with-config-file-path=/data1/server/php-cgi/etc --with-zlib --enable-exif --enable-ftp --with-xmlrpc --enable-zip --with-iconv-dir --with-libxml-dir --with-mcrypt --with-tidy --with-tidy --enable-fpm

出现错误
configure: error: xml2-config not found. Please check your libxml2 installation.

1.安装他
#apt-get install libxml2-dev

错误
configure: error: Please reinstall the libcurl distribution –
easy.h should be in <curl-dir>/include/curl/

2.安装他
apt-get install libcurl4-gnutls-dev

错误
configure: error: jpeglib.h not found.
3.安装他
apt-get install libjpeg-dev

错误
If configure fails try –with-vpx-dir=<DIR>
configure: error: png.h not found.
4.安装他
apt-get install libpng12-dev

错误
If configure fails try –with-xpm-dir=<DIR>
configure: error: freetype.h not found.
5.安装他
apt-get install libfreetype6-dev

错误
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
6.安装他
apt-get install libmcrypt-dev

错误
configure: error: Cannot find libtidy
7.安装他
apt-get install libtidy-dev

加强版本

apt-get install libxml2-dev -y
apt-get install libcurl4-gnutls-dev -y
apt-get install libjpeg-dev -y
apt-get install libpng12-dev -y
apt-get install libfreetype6-dev -y
apt-get install libmcrypt-dev -y
apt-get install libtidy-dev -y

我一个一个测试的。大家安装的时候,可以先安装这些错误需要安装的东西,然后再执行./configure……

make
make test
make install

参考资料
http://hi.baidu.com/snailzzz/blog/item/d61de8452e477d2dcefca3b0.html

启动php-fpm

/data1/server/php-cgi/sbin/php-fpm

错误
[28-Mar-2012 11:15:01] ERROR: failed to open configuration file ‘/data1/server/php-cgi/etc/php-fpm.conf’: No such file or directory (2)
[28-Mar-2012 11:15:01] ERROR: failed to load configuration file ‘/data1/server/php-cgi/etc/php-fpm.conf’
[28-Mar-2012 11:15:01] ERROR: FPM initialization failed
cd /data1/server/php-cgi/etc

再次启动
/data1/server/php-cgi/sbin/php-fpm

ERROR: [pool www] cannot get gid for group ‘nobody’
好吧,我们加一个组叫nobody

#groupadd nobody

再次启动
/data1/server/php-cgi/sbin/php-fpm
成功了。

关闭php-fpm
killall php-fpm

目前还不知道有没有直接的命令来关闭它。

cannot get gid for group ‘nobody’ 其他解决方案。
————————————————————————————
or can change it in your php-fpm.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user’s group
; will be used.
user = www-data
group = nobody
————————————————————————————-

集成nginx

最后的配置
# cd /etc/nginx/conf.d
#vi default.conf

location ~ \.php$ {

root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;

# vi /etc/nginx/fastcgi.conf

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 only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

/etc/init.d/nginx stop
/etc/init.d/nginx start

成功啦。

给php一个配置文件,从安装目录拷贝一个
cp php.ini-development /data1/server/php-cgi/etc/php.ini



This entry was posted in Linux, PHP, 高并发与大数据 and tagged , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/nginx-php-fpm/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力

One Response to nginx 下配置php-FPM

  1. Aakash says:

    说:突然想说一句半题外话,呵呵:我们发现,对于 nginx + php farm 的并发性能影响最大的经常是,当 php 发起到 DB 或者 memcached 或者后端 HTTP sevrice 时,当前 php 进程是阻塞的。因此我们打算试试让 php 进程需要发起二级 IO 请求时,直接由 nginx 的 subrequest 来代理之,这样,php 端的 IO 便可以与 nginx 的性能极好的 event model 融为一体,从而提升单机整体的并发能力。(这对于 Perl/Python/Ruby/Haskell/V8 等其他的以 fastcgi 形式挂在 nginx 后面的 web 应用亦是适用的。)因此我们需要借用 fastcgi 协议去支持 fastcgi 后端直接发起 nginx subreqest,并传递 subrequest 完成后需要打开的“continuation 对象”,并结果和控制权重新交回指定的 fastcgi 后端入口。

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

  

  

About Me

静水流深,水滴石穿