PHP与PHP-FPM的安装
- 下载安装包
从www.php.net官网下载php源码包,这里下载的是php-5.2.17.tar.bz2,
从http://php-fpm.org/downloads/下载对应的PHP-FPM源码包,这里下载的是php-5.2.17-fpm-0.5.14.diff.gz
2.开始编译安装PHP和PHP-FPM
[[email protected] ~]# tar jxf php-5.2.17.tar.bz2
[[email protected] ~]# gzip -cd php-5.2.17-fpm-0.5.14.diff.gz |patch -d php-5.2.17 -p1
[[email protected] ~]# cd php-5.2.17
[[email protected] php-5.2.17]# ./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm
[[email protected] php-5.2.17]# make &&make install
[[email protected] php-5.2.17]# cp php.ini-dist /usr/local/php/lib/php.ini
3.配置PHP-FPM的默认配置文件
[[email protected] php-5.2.17]# vim /usr/local/php/etc/php-fpm.conf
Unix user of processes
<value name="user">nobody</value>
Unix group of processes
<value name="group">nobody</value>
Process manager settings
大概62行,去掉这两行的注释
4.启动FastCGI进程
[[email protected] php-5.2.17]# /usr/local/php/bin/php-cgi --fpm
或
[[email protected] php-5.2.17]# /usr/local/php/sbin/php-fpm start
查看端口和进程是否启动
[[email protected] php-5.2.17]# netstat -antl| grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
[[email protected] php-5.2.17]# ps -ef | grep php-cgi
root 6922 1 0 16:44 ? 00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf
nobody 6923 6922 0 16:44 ? 00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf
nobody 6924 6922 0 16:44 ? 00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf
nobody 6925 6922 0 16:44 ? 00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf
nobody 6926 6922 0 16:44 ? 00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.conf
nobody 6927 6922 0 16:44 ? 00:00:00 /usr/local/php/bin/php-cgi --fpm --fpm-config /usr/local/php/etc/php-fpm.con
5.配置Nginx支持PHP
[[email protected] php-5.2.17]# vim /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
# ‘$status $body_bytes_sent "$http_referer" ‘
# ‘"$http_user_agent" "$http_x_forwarded_for"‘;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name 192.168.8.64;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
index index.html index.php;
}
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
重新启动Nginx进程
[[email protected] php-5.2.17]# ps -ef | grep nginx
root 6946 1 0 16:49 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 6947 6946 0 16:49 ? 00:00:00 nginx: worker process
[[email protected] php-5.2.17]# kill 6946
[[email protected] php-5.2.17]# /usr/local/nginx/sbin/nginx
到此为止,Nginx+PHP已配置完成
6.测试Nginx对PHP的解析功能
在/usr/local/nginx/html目录下创建一个phpinfo.php文件,内容如下:
<?php phpinfo(); ?>
在浏览器中访问 http://192.168.8.64/phpinfo.php,如果能正常解析,会出现PHP安装配置以及功能列表统计信息。
Nginx与PHP(FastCGI)的安装、配置,布布扣,bubuko.com