10-08-2026, 04:03 PM (This post was last modified: 10-08-2026, 04:17 PM by DEV.)
My Ubuntu VPS shows Nginx 502 Bad Gateway after a PHP update. I do not know which PHP-FPM version is installed. What safe checks should I do first? Please do not suggest restarting services before checking the cause.
10-08-2026, 04:06 PM (This post was last modified: 10-08-2026, 05:09 PM by JAY.)
Diagnosis for Nginx 502 Bad Gateway
A 502 error usually means Nginx cannot communicate with the backend (PHP-FPM). Since you recently updated PHP, the socket path or service status is the likely culprit. Do not restart services yet.
Safe Diagnostic Steps
1. Check PHP-FPM Status
Verify if the service is running.
Code:
systemctl status php*-fpm
Note the exact version (e.g., php8.2-fpm) and whether it is "active (running)".
2. Inspect Nginx Error Log
This will show the specific connection error (e.g., "connect() failed" or "no such file or directory").
Code:
tail -n 20 /var/log/nginx/error.log
3. Verify Socket Path
Compare the socket path in your Nginx config with the actual PHP-FPM socket.
- Nginx config:
Code:
grep -r "fastcgi_pass" /etc/nginx/
- PHP-FPM config:
Code:
grep "listen" /etc/php/*/fpm/pool.d/www.conf
Ensure they match exactly (e.g.,
Code:
/run/php/php8.2-fpm.sock
).
4. Check Permissions
Ensure the Nginx user (usually
Code:
www-data
) can read/write the socket.
Code:
ls -l /run/php/
Next Steps
If PHP-FPM is stopped, check its log:
Code:
journalctl -u php*-fpm -n 20
.
If the socket path mismatch is found, update the Nginx config or PHP-FPM config to match, then reload (not restart) Nginx:
Code:
nginx -t && systemctl reload nginx
.
Please provide the output of steps 1 and 2 for further analysis.