PHP-FPM connect() to unix:/tmp/php5-fpm.sock failed (2: No such file or directory)
Today I was investigating a weird issue on a VPS box with a simple PHP-FPM, Nginx and MySQL stack. The problem was the main website was facing a 502 Bad Gateway error. I found this logs:
2014/07/31 04:12:53 [crit] 20630#0: *8895466 connect() to unix:/tmp/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 108.162.xx.xx, server: website.com, request: "GET /stream/media/34b53d13851f61b5fa76a38148996643/6ee0218e84b123c0c84e98310176fdfc/1/bb91dc8d8e756434b1e3e1490e5bd4b8/ HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: "website.com", referrer: "http://website.com/assets/images/players/jkplayer.swf" 2014/07/31 04:12:53 [crit] 20630#0: *8895468 connect() to unix:/tmp/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 188.114.xx.xx, server: website.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: "website.com"
The error can be resumed pretty easy into this line:
connect() to unix:/tmp/php5-fpm.sock failed (2: No such file or directory)
However, the socket was created and there:
srw-rw-rw- 1 nginx nginx 0 Jul 31 05:57 /tmp/php5-fpm.sock
Permissions, owner and the file was OK but Nginx still didn’t pick up the php-fpm socket.
I even tried to move the socket to another directory like /var/run (as suggested by other users on the internet) but it wasn’t working too. The only thing that did the trick was to switch from unix socket to php-fpm default port at 9000.
nano -w /etc/php-fpm.d/www.conf
Then I set the listen variable as you see below:
listen = 127.0.0.1:9000;
And do the same on Nginx configuration file:
nano -w /etc/nginx/conf.d/site.com.conf
Set the fastcgi_pass variable to use the 9000 port we specified at php-fpm before:
fastcgi_pass 127.0.0.1:9000;
This was the first time I saw this error on a plain CentOS, with the php-fpm + nginx stack. This quick fix was useful to get the site up and running fast to avoid more downtime, however I will dig into the real cause of the issue, anyway, hope it helps you to quickly fix it in case you have the same issue.
Popular search terms:
- PHP-FPMconnect()tounix:/tmp/php5-fpm sockfailed(2:Nosuchfileordirectory)|NginxTips
- connect() to unix:/run/php/php5 6-fpm sock failed (2: No such file or directory)
- connect() to unix:///tmp/meisheng sock failed (2: No such file or directory)
- https://www scalescale com/tips/nginx/php-fpm-connect-to-unixtmpphp5-fpm-sock-failed-2-no-such-file-or-directory/