sfw/fix
2: No such file or directory critical

nginx 502: connect() to unix:/run/php/php-fpm.sock failed (2: No such file or directory)

nginx can't find the PHP-FPM socket file, so PHP pages return 502 — FPM is down or the socket path is wrong.

What you see

connect() to unix:/run/php/php-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 203.0.113.7, server: example.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php-fpm.sock"

What’s actually happening

Every PHP page throws a 502 Bad Gateway and nginx's error.log shows this line. The socket file nginx is dialing isn't there. Two reasons it's missing: PHP-FPM isn't running (crashed, never started, or stopped after an upgrade), so nothing created the socket — or FPM is running fine but listening on a different path than the one in your fastcgi_pass. Static files still serve; only PHP is dead.

Common causes

  • PHP-FPM isn't running — failed to start, crashed, or was left stopped after a package update
  • The fastcgi_pass path in nginx doesn't match the listen= in the FPM pool (e.g. /run/php/php-fpm.sock vs /run/php/php8.2-fpm.sock)
  • A PHP version upgrade changed the socket name and the nginx config still points at the old one
  • The FPM pool is set to listen on a TCP port (127.0.0.1:9000) while nginx is configured for a unix socket, or vice-versa
  • A permissions or path issue on /run/php stops the socket from being created where nginx expects it

How to fix it

  1. Check whether PHP-FPM is actually runningsystemctl status php8.2-fpm (match your version). If it's dead, systemctl start php8.2-fpm and watch for it to come up. If it won't start, journalctl -u php8.2-fpm -n50 usually names the reason — a syntax error in a pool .conf or a bad chdir.
  2. Confirm the socket exists and wherels -l /run/php/ — note the exact socket filename. Compare it to listen = in /etc/php/8.2/fpm/pool.d/www.conf. That listen value is the source of truth for the path.
  3. Make nginx's fastcgi_pass match the pool's listenSet fastcgi_pass unix:/run/php/php8.2-fpm.sock; in your server block to exactly match the pool. After a PHP upgrade this is the usual culprit — the socket got a version in its name and nginx never followed. nginx -t, then systemctl reload nginx.
  4. Decide socket vs TCP and keep both ends consistentIf the pool uses listen = 127.0.0.1:9000, nginx must use fastcgi_pass 127.0.0.1:9000; — not a unix path. Pick one transport and set it identically on both sides.
  5. Enable FPM on bootsystemctl enable php8.2-fpm so a reboot doesn't leave you with a missing socket and a site full of 502s.

Stop it recurring

After any PHP version upgrade, grep your nginx configs for the old socket name and run nginx -t before reloading.

Related errors