How to fix a stuck PHP-FPM service on Ubuntu (502 Bad Gateway)
Your Nginx site is down with a 502 Bad Gateway. You restart PHP-FPM and get an error like Job for php8.3-fpm.service failed.... Here's the quick, reliable way I fix it.
1) Find the real problem
When systemctl shows a failure like status=78, it often points to a bad configuration. Start by testing the config:
sudo php-fpm8.3 -tIf this passes but the service still won't start, check full service logs:
sudo journalctl -xeu php8.3-fpm.serviceLook for an ERROR line similar to:
ERROR: Another FPM instance seems to already listen on /var/run/php/your-socket-name.sockThis means an old/stuck PHP-FPM process is still bound to the socket, blocking the new instance.
2) The fix: clear the old process
In the commands below, replace /var/run/php/your-socket-name.sock with the actual socket path from your error log.
- Find the stuck process (PID) - sudo lsof /var/run/php/your-socket-name.sock- This prints the process holding the socket (likely running as - root). Note its PID.
- Stop that process - # Replace 12345 with the actual PID sudo kill 12345- If it refuses to die after a few seconds, you can force kill it (use cautiously): - sudo kill -9 12345
- Remove the stale socket file - sudo rm /var/run/php/your-socket-name.sock- PHP-FPM will recreate it when it starts. 
- Start PHP-FPM - sudo systemctl start php8.3-fpm- Your service should now start cleanly. Verify status: - systemctl status php8.3-fpm
3) Why this happens
If PHP-FPM crashes or is killed unexpectedly, it can leave a running child or a stale socket behind. Systemd tries to start a fresh master process, but the socket is already taken.
4) Prevent it next time
- Graceful restarts: Prefer systemctl reload php8.3-fpmfor config changes.
- Watch logs: Monitor /var/log/php8.3-fpm.log(or your distro path) for crashes.
- Socket vs. port: If you keep hitting socket conflicts, consider TCP (127.0.0.1:9000) temporarily while you debug.
Quick copy-paste checklist
# 1) Sanity-check config
sudo php-fpm8.3 -t
# 2) Inspect service logs
sudo journalctl -xeu php8.3-fpm.service
# 3) If "already listen" error -> free the socket
sudo lsof /var/run/php/your-socket-name.sock
sudo kill <PID>
sudo rm /var/run/php/your-socket-name.sock
# 4) Start service
sudo systemctl start php8.3-fpm
# 5) Verify
systemctl status php8.3-fpm