ScaleScaleScaleScale

Tips / Nginx


PHP-FPM connect() to unix:/tmp/php5-fpm.sock failed (2: No such file or directory)

phpfpm

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/
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Erik

    You really want to use the unix sock file. It way faster then building a TCP socket to connect to a running process.

    Add this to your nginx config in side a location ~ .php$ { }
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

    For the php-fpm add
    listen = /var/run/php-fpm/php-fpm.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0666

    Edit the paths to your liking.

    you should get a decent speed increase.

  • Cokaric

    I was receiving following
    (mod_fastcgi.c.1754) connect failed: No such file or directory on unix:/tmp/php5-fpm.sock
    (mod_fastcgi.c.3021) backend died; we’ll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1
    (mod_fastcgi.c.2848) fcgi-server re-enabled: unix:/tmp/php5-fpm.sock

    I fixed my issue by changing path in /etc/php-fpm.d/www.conf and /etc/lighttpd/conf.d/fastcgi.conf to /var/run/php5-fpm.sock

    /etc/php-fpm.d/www.conf >>
    listen = /var/run/php5-fpm.sock

    also I have
    listen.owner = lighttpd
    listen.group = lighttpd
    listen.mode = 0666

    user = lighttpd
    ; RPM: Keep a group allowed to write in log dir.
    group = lighttpd

    /etc/lighttpd/conf.d/fastcgi.conf >>
    fastcgi.server = (
    “.php” => ((
    # “host” => “127.0.0.1”,
    # “port” => “9000”,
    “socket” => “/var/run/php5-fpm.sock”,
    “broken-scriptfilename” => “enable”
    # “docroot” => “/srv/www/servers/www.example.org/htdocs/”
    )))

    Use nginx for user/group for nginx webserver, www-data for httpd, apache for apache and lighttpd for lighttpd 🙂

  • Hike Nalbandyan

    This is amazing thank you!