安装php5-fpm
# apt-get install php5-fpm
安装完成以后修改/etc/php5/fpm/conf.d/www.conf:
;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000
重载php5-fpm配置
# /etc/init.d/php5-fpm reload
检查一下是否监听了9000端口:
# netstat -tln
如果出现了9000端口,说明php5-fpm正常启动。
安装完成之后配置/etc/nginx/conf.d/default.conf:
要执行php关键要修改如下部分:
#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;
# }
去掉前面的#号,修改root为你自己目录,修改/scripts$fastcgi_script_name为$document_root$fastcgi_script_name。修改之后如下:
location ~ \.php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
注意:
root如果不指定会出现找不到文件的错误。
/scripts如果不修改会出现如下错误
[error] 5152#0: *7 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"
也可以不指定root直接把$document_root写成真实地址。
如果不修改/etc/php5/fpm/conf.d/www.conf的话,也可以设置fastcgi_pass 后的127.0.0.1:9000;为unix:/var/run/php5-fpm.sock;
然后重载nginx配置:
# /etc/init.d/nginx reload
在/var/www目录中新建一个index.php文件,在浏览器地址栏输入localhost,回车!