PHP-FPM socket errors are one of the most common causes of Nginx 502 errors. The fix is usually quick once you identify the exact cause.
Common Error Messages
# Nginx error log shows:
connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory)
connect() to unix:/run/php/php8.2-fpm.sock failed (13: Permission denied)
connect() failed (111: Connection refused) while connecting to upstream
Step 1 — Check PHP-FPM Status
sudo systemctl status php8.2-fpm
sudo journalctl -u php8.2-fpm -n 50
Step 2 — "No such file" — Socket Missing
# Start PHP-FPM
sudo systemctl start php8.2-fpm
# Check socket created
ls -la /run/php/php8.2-fpm.sock
# If service fails to start, check config
sudo php-fpm8.2 --test
Step 3 — "Permission denied" — Fix Socket Permissions
sudo nano /etc/php/8.2/fpm/pool.d/www.conf
; Must match Nginx worker user
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
; Also check user/group
user = www-data
group = www-data
sudo systemctl restart php8.2-fpm nginx
Step 4 — CWP/Control Panel Overwriting Config
# CWP daily cron overwrites PHP-FPM pool configs
# Permanent fix — add to pool config:
listen.group = nobody
# Check if cron is overwriting
sudo crontab -l | grep php
ls /etc/cron.daily/ | grep php
Step 5 — Wrong Socket Path in Nginx
# Find actual socket location
find /run /var/run -name "*.sock" 2>/dev/null | grep php
# Update Nginx config to match
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
# Restart Nginx
sudo nginx -t && sudo systemctl reload nginx
Conclusion
PHP-FPM socket errors are always fixable. Our team provides emergency server support for PHP-FPM and Nginx issues.
Comments