502 Bad Gateway Checklist for Nginx PHP-FPM
A 502 Bad Gateway error usually means Nginx cannot communicate properly with the backend service. On WordPress or PHP websites, the backend is often PHP-FPM. This checklist helps you check Nginx, PHP-FPM, socket configuration, service status, logs and server resources in the correct order.
Common causes
- PHP-FPM is stopped.
- PHP-FPM socket path is wrong.
- Nginx server block points to the wrong backend.
- PHP-FPM is overloaded.
- RAM is exhausted.
- Recent PHP or Nginx config changes broke the site.
Checklist
- Confirm whether the error affects the whole website or only PHP pages.
- Run nginx -t to validate Nginx config.
- Check Nginx service status.
- Check PHP-FPM service status.
- Verify the PHP-FPM socket or upstream address in the Nginx config.
- Check RAM and CPU usage.
- Read Nginx error log.
- Read PHP-FPM log if available.
- Restart PHP-FPM only if it is failing.
- Reload Nginx after fixing config.
Final check
A 502 error should not be fixed by random restarts. The correct fix is to identify whether Nginx, PHP-FPM, socket path, permissions or server resources caused the failure.
When to Use This Checklist
Use this checklist when a WordPress or PHP website behind Nginx returns a 502 Bad Gateway error.
Required Tools
SSH access, Nginx, PHP-FPM, server block config, Nginx error log, PHP-FPM log, VPS access
Before You Start
Do not edit multiple config files at once. First confirm the PHP version and the PHP-FPM service name used by the website.
Structured Checklist Steps
- Check whether all PHP pages are affected.
- Run nginx -t.
- Check Nginx status.
- Check PHP-FPM status.
- Verify fastcgi_pass socket path.
- Check RAM and CPU.
- Read Nginx error log.
- Read PHP-FPM log.
- Restart PHP-FPM if needed.
- Reload Nginx after config fix.
Verification Steps
- Open homepage.
- Open wp-admin if this is WordPress.
- Run nginx -t again.
- Confirm error log has no new upstream errors.
- Check PHP-FPM remains active.
Rollback Plan
If a config edit caused the 502 error, restore the previous Nginx server block or PHP-FPM pool config, then reload Nginx and restart PHP-FPM.
Common Mistakes
- Restarting Nginx without checking PHP-FPM.
- Using the wrong PHP socket path.
- Editing multiple configs at once.
- Ignoring RAM exhaustion.
- Forgetting to run nginx -t before reload.
Related Commands
sudo nginx -t
sudo systemctl status nginx
sudo systemctl status php8.2-fpm
sudo tail -n 100 /var/log/nginx/error.log
free -h
df -h
sudo systemctl restart php8.2-fpm
sudo systemctl reload nginx