I update nginx to 1.4.7 and php to 5.5.12, After that I got the 502 error. Before I update everything works fine.
nginx-error.log
2014/05/03 13:27:41 [crit] 4202#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: xx.xxx.xx.xx, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xx.xx.xx.xx"
nginx.conf
user www www;
worker_processes 1;
location / {
root /usr/home/user/public_html;
index index.php index.html index.htm;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/home/user/public_html$fastcgi_script_name;
include fastcgi_params;
}
@Xander's solution works, but does not persist after a reboot.
I found that I had to change
listen.mode
to0660
in/etc/php5/fpm/pool.d/www.conf
.Sample from www.conf:
Edit: Per @Chris Burgess, I've changed this to the more secure method.
I removed the comment for listen.mode, .group and .owner:
/var/run Only holds information about the running system since last boot, e.g., currently logged-in users and running daemons. (http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard#Directory_structure).
Side note:
My
php5-fpm -v
Reports:PHP 5.4.28-1+deb.sury.org~precise+1
. The issue did happen after a recent update as well.In fact, "listen.mode" should be: "0660" and not "0666" as Other Writable or Other Readable is never a good choice here.
So try to find out as which user/group your webserver runs. I use CentOs and it runs as user "nginx" So add to your php-fpm.conf:
finally restart php-fpm
After upgrading from Ubuntu 14.04 lts to Ubuntu 16.04 lts I found a yet another reason for this error that I haven't seen before.
During the upgrading process I had somehow lost my php5-fpm executable altogether. All the config files were intact and it took me a while to realize that
service php5-fpm start
didn't really start a process, as it did not show any errors.My moment of awakening was when I noticed that there were no socket file in
/var/run/php5-fpm.sock
, as there should be, nor didnetstat -an
show processes listening on the port that I tried as an alternative while trying to solve this problem. Since the file /usr/sbin/php5-fpm was also non-existing, I was finally on the right track.In order to solve this problem I upgraded php from version 5.5 to 7.0.
apt-get install php-fpm
did the trick as a side effect. After that and installing other necessary packages everything was back to normal.This upgrading solution may have problems of its own, however. Since php has evolved quite a bit, it's possible that the software will break in unimaginable ways. So, even though I did go down that path, you may want to keep the version you're fond of just for a while longer.
Luckily, there seems to be a neat way for that, as described on The Customize Windows site:
Neater solution as it might be, I didn't try that. I expect the next couple of days will tell me whether I should have.
Also check SELINUX (/etc/selinux):
turn it off:
Simple but works..
If you have different pool per user make sure user and group are set correctly in configuration file. You can find nginx user in /etc/nginx/nginx.conf file. nginx group is same as nginx user.