I recently upgraded some PHP packages on an Cloud VPS server and since that I noticed some errors on the hosted websites. The first thing I noticed was a 502 Gateway timeout error. And after reviewing the logs I found this:
[crit] 2963#0: *138 connect() to unix:/tmp/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
The first thing I did to get the websites up and running asap was this:
nano -w /etc/php-fpm.d/www.conf
And set the listen line to look as follows:
listen = 127.0.0.1:9000
Then I switched back to :9000 port at PHP-FPM configuration and at each nginx virtual host configuration altering:
Reloaded nginx and php-fpm and the web was finally working.
But why php-fpm socket was failing?
And the problem was pretty simple: file permissions & owner.
What was the cause of the problem?
When I updated this php* packages, something changed and since that the php-fpm socket was created with this file permissions and owner:
[email@example.com:~]ls -ahl /tmp/php5-fpm.sock srw-rw---- 1 root root 0 May 6 08:08 /tmp/php5-fpm.sock
That was the reason Nginx was not able to connect to the php-fpm socket.
In order to fix the php5-fpm.sock failed error follow these instructions
1) Make sure your virtual hosts nginx (.conf) files are using fastcgi_pass unix:/tmp/php5-fpm.sock; at the php-fpm configuration.
2) Edit nginx.conf file and make sure this variable is as follow:
3) Edit /etc/php-fpm.d/www.conf file and set this variables as you see below:
listen = /tmp/php5-fpm.sock listen.owner = nginx listen.group = nginx
4) Reload your services:
service nginx reload service php-fpm reload
All done, your websites now shouldn’t face any more 502 permission/owner issues because the socket has the same group as Nginx:
[firstname.lastname@example.org:~]ls -ahl /tmp/php5-fpm.sock srw-rw---- 1 nginx nginx 0 May 6 08:08 /tmp/php5-fpm.sock
At this point, if you are still facing 502 Gateway timeout issues, check out this other post:
Popular search terms:
- HowtoFixphp5-fpm sockfailed(13:Permissiondenied)error
- unix:/var/run/php-fpm-errorpages sock
- drupal8 php-fpm file permissions
- php 5 6 fpm sock failed