今天在安装配置Ubuntu系统下的PHP环境,首先安装:



sudo apt-get install mysql-server
sudo apt-get install nginx
sudo apt-get install php5-fpm
sudo apt-get install php5-cli php5-gd php5-mysql



    接着修改nginx配置:



vim /etc/nginx/sites-available/default

server {
listen 80 default_server;
server_name localhost;
root /var/www;
index index.php index.html;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

# php5-fpm 配置信息
location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

}



     然后启动nginx、php5-fpm,访问localhost 下的phpinfo.php 文件时,总算报错:502.

     前前后后检查了几遍后,终于发现问题所在:php5-fpm监听方式错误。

      打开php5-fpm配置文件(/etc/php5/fpm/pool.d/www.conf),发现其监听方式为socket,而不是9000端口,如下所示:



; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock



      于是修正nginx中对应配置即可,reload后再访问就ok了!

      网上有人说ubuntu 1210默认安装php5-fpm无监听9000端口,本人无考证。

      对于两者性能找了篇文章,仅供参考:

      ​​https://rtcamp.com/tutorials/php/fpm-sysctl-tweaking/​

      ​​http://www.cnxct.com/default-configuration-and-performance-of-nginx-phpfpm-and-tcp-socket-or-unix-domain-socket/​