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.
Estimated Time
Use Case
Use this checklist when a WordPress or PHP website behind Nginx returns a 502 Bad Gateway error.
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