Nginx + PHP-FPM 502 Bad Gateway: connect() to php8.3-fpm.sock failed (Permission denied)
PHP-FPM pool `listen.owner`/`listen.group` does not match Nginx worker user (`www-data`).
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: Nginx + PHP-FPM 502 Bad Gateway
Platform: PHP
Common Root Causes:
- PHP-FPM pool `listen.owner`/`listen.group` does not match Nginx worker user (`www-data`).
Interactive Diagnostic Checklist
Verified Solutions:
- Set `listen.owner = www-data; listen.group = www-data; listen.mode = 0660;` and reload php-fpm.
Safe Diagnostic Command:
ls -l /run/php/ && grep -E "^(user|group|listen)" /etc/php/*/fpm/pool.d/www.conf
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
PHP-FPM pool `listen.owner`/`listen.group` does not match Nginx worker user (`www-data`). Recommended diagnostic: `ls -l /run/php/ && grep -E "^(user|group|listen)" /etc/php/*/fpm/pool.d/www.conf`. Remediation: Set `listen.owner = www-data; listen.group = www-data; listen.mode = 0660;` and reload php-fpm.
Worked Examples
- Run `ls -l /run/php/ && grep -E "^(user|group|listen)" /etc/php/*/fpm/pool.d/www.conf` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-php-fpm-502-sock-permission · Independently verified: 2026-11-25