GrepBoard/Manuals
605 manuals ·

Fix nginx 502 php-fpm www.sock failed (13: Permission denied)

·Tested on Rocky Linux 9.8 (Docker rockylinux:9) · nginx 1.20.1 · PHP-FPM 8.0.30 · 2026-10·Test scope ↓·7 steps

nginx 502 with www.sock failed (13: Permission denied) means the worker user cannot write to the PHP-FPM socket. Add it to listen.acl_users or set listen.owner.

output
2026/10/27 08:52:03 [crit] 304#304: *3 connect() to unix:/run/php-fpm/www.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: _, request: "GET /t.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "127.0.0.1"

The user that runs the nginx worker processes has no write permission on the PHP-FPM Unix socket /run/php-fpm/www.sock, so nginx returns 502. Add the worker user to listen.acl_users in /etc/php-fpm.d/www.conf, or, for a pool that does not use ACLs, set listen.owner and listen.group to that user, then restart PHP-FPM. The output below comes from a Rocky Linux 9 container where the settings were broken on purpose.

[1] Read the number in parentheses first. The same connect() to unix:… failed line points to different places depending on the number. In error.log this line is logged at [crit], not [error].

MessageMeaningWhere to look
(13: Permission denied)The socket exists but the worker cannot write to itSteps [2]–[6]; if permissions are right, [7] SELinux
(2: No such file or directory)The socket file does not existPHP-FPM is down, or its listen path differs from nginx's
(111: Connection refused)Nothing listens on the TCP portnginx 502 error log messages

With PHP-FPM stopped, the line showed (2: …) and the socket directory was empty.

console
# tail -n 1 /var/log/nginx/error.log2026/10/27 08:52:15 [crit] 490#490: *11 connect() to unix:/run/php-fpm/www.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: _, request: "GET /t.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/www.sock:", host: "127.0.0.1"# ls -l /run/php-fpm/total 0

[2] Check which user the nginx workers run as. The master runs as root; the workers that handle requests use the user value in nginx.conf. The Rocky package default is user nginx;, and the PHP-FPM workers run as apache.

console
# ps -o user,comm -C nginx,php-fpmUSER     COMMANDroot     php-fpmapache   php-fpmapache   php-fpmapache   php-fpmapache   php-fpmapache   php-fpmroot     nginxnginx    nginxnginx    nginxnginx    nginxnginx    nginx

[3] Look at the socket permissions. With the default config, ls -l shows a + after the mode bits and getfacl lists user:nginx:rw-. The root root owner is normal: access is granted through the ACL.

console
# ls -l /run/php-fpm/www.socksrw-rw----+ 1 root root 0 Oct 27 08:51 /run/php-fpm/www.sock# getfacl -p /run/php-fpm/www.sock
output
# file: /run/php-fpm/www.sock# owner: root# group: rootuser::rw-user:apache:rw-user:nginx:rw-group::rw-mask::rw-other::---

The first three lines of getfacl output (# file: and so on) are a header, not commands.

After commenting out the listen.acl_users line and restarting, the + disappeared and only root root srw-rw---- was left. That state produces the 502. Testing write access as the worker user shows it directly.

console
# ls -l /run/php-fpm/www.socksrw-rw---- 1 root root 0 Oct 27 08:52 /run/php-fpm/www.sock# su -s /bin/sh nginx -c "test -w /run/php-fpm/www.sock && echo writable || echo not-writable"not-writable

[4] Open the pool config. Rocky's default www.conf leaves listen.owner, group and mode commented out and grants apache and nginx access through listen.acl_users.

console
# grep -nE '^;?listen\.(owner|group|mode|acl_users|acl_groups)' /etc/php-fpm.d/www.conf48:;listen.owner = nobody49:;listen.group = nobody50:;listen.mode = 066055:listen.acl_users = apache,nginx56:;listen.acl_groups =
output
[27-Oct-2026 08:52:07] WARNING: [pool www] ACL set, listen.owner = 'nginx' is ignored[27-Oct-2026 08:52:07] WARNING: [pool www] ACL set, listen.group = 'nginx' is ignored

Before changing anything, do two things: copy the pool config, and confirm from the ps output in [2] that the account you are about to add is the actual nginx worker (the user on the worker lines, not the master's root). Adding the wrong account leaves the 502 in place and only widens access.

console
# cp -a /etc/php-fpm.d/www.conf /root/www.conf.bak# grep -E '^\s*user\s' /etc/nginx/nginx.conf

⚠️ The systemctl restart php-fpm in [5] and [6] restarts every PHP-FPM worker, so PHP requests in progress are cut off, and while it restarts the socket is missing and requests briefly get the (2: …) 502. Do it at a quiet time, and restart only after php-fpm -t passes.

[5] For a pool that uses ACLs, add the worker user to listen.acl_users. Below is the fix after user in nginx.conf was changed to web and requests got 502. Separate names with commas, no spaces in between.

/etc/php-fpm.d/www.conf
listen.acl_users = apache,nginx,web
console
# php-fpm -t[27-Oct-2026 08:52:12] NOTICE: configuration file /etc/php-fpm.conf test is successful # systemctl restart php-fpm# getfacl -p /run/php-fpm/www.sock
output
# file: /run/php-fpm/www.sock# owner: root# group: rootuser::rw-user:apache:rw-user:web:rw-user:nginx:rw-group::rw-mask::rw-other::---

[6] For a pool without ACLs (a separate pool file with no listen.acl_users line), make the worker user the owner. Uncomment the three lines and change the values. To use this method in the default www.conf, also comment out the listen.acl_users line (line 55) with ;, as [4] warns; the test did the same.

/etc/php-fpm.d/www.conf
listen.owner = nginxlisten.group = nginxlisten.mode = 0660

As in [5], restart only after php-fpm -t prints test is successful.

console
# systemctl restart php-fpm# ls -l /run/php-fpm/www.socksrw-rw---- 1 nginx nginx 0 Oct 27 08:52 /run/php-fpm/www.sock# curl -si http://127.0.0.1/t.php | sed -n '1p;$p'HTTP/1.1 200 OKok

PHP-FPM creates the socket when it starts. After a change, restart it and check the result with ls -l; reload nginx (nginx -s reload) only if you changed nginx.conf.

If php-fpm -t fails, or PHP-FPM does not come back after the restart, restore the copy, check it, and start again. Look for the cause in journalctl -u php-fpm and /var/log/php-fpm/error.log.

console
# cp -a /root/www.conf.bak /etc/php-fpm.d/www.conf && php-fpm -t && systemctl restart php-fpm

[7] If permissions are right and (13: Permission denied) persists, check SELinux. When the socket lives somewhere other than /run/php-fpm, or a file label is off, SELinux blocking nginx produces the same number. Follow nginx proxy blocked by SELinux and httpd 403 from SELinux to find the denial and fix the labels.

console
# ausearch -m AVC -ts recent

For a different error when Apache httpd hands requests to PHP-FPM, see AH01071 Primary script unknown.

Analyze your Nginx log in the browser ↗ — nothing is uploaded.

Check it with the HTTP status codes tool ↗ — calculated in your browser.

#nginx#php-fpm#rocky#502