利用upgrade_php.sh脚本升级了下lnmp中的php到5.3.29,然后发现所有php页面都502错误了,经过检查日志发现,nginx尝试去访问php-fpm的sock,我这里是用的/tmp/php-fpm.sock,但是php-fpm的日志并没有任何记录,
ls -alh /tmp/php-fpm.sock
后发现,显示如下:
srw------- 1 root root 0 12月 2 22:17 /tmp/php-cgi.sock
感觉似乎有那么点不对劲,为嘛是root,而且,只有root可读可写。
检查php-fpm的配置文件发现如下:
[global] pid = /usr/local/php/var/run/php-fpm.pid error_log = /usr/local/php/var/log/php-fpm.log log_level = notice [www] listen = /tmp/php-cgi.sock user = www group = www pm = dynamic pm.max_children = 20 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 6 request_terminate_timeout = 100
查看相关文档发现,没有设置listen的所有者和文件权限,修改后如下(修改部分见高亮部分):
[global] pid = /usr/local/php/var/run/php-fpm.pid error_log = /usr/local/php/var/log/php-fpm.log log_level = notice [www] listen = /tmp/php-cgi.sock user = www group = www listen.owner = www listen.group = www listen.mode = 0660 pm = dynamic pm.max_children = 20 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 6 request_terminate_timeout = 100
测试,问题解决。