PHP-FPM socket troubleshooting
Troubleshoot from the listener inward
A 502 often indicates Nginx could not obtain a usable upstream response; a 504 often indicates an upstream timeout before a response can be sent. A 404 may come from the front-end file check or from PHP. A 500 may come from a script error. None of these status codes uniquely identifies the cause. Check the configured listener, pool readiness, Nginx error log, FPM logs and an approved request. Keep diagnostics free of credentials and user data.
connect() failed (111: Connection refused) while connecting to upstreamconnect() to unix:/run/bytemind-fpm/lab.sock failed (13: Permission denied)FastCGI sent in stderr: "Primary script unknown"upstream timed out while reading response header from upstreamConnection refusal suggests a wrong address or absent listener. Permission denied on a Linux socket calls for inspection of the directory traversal permissions, socket owner/group/mode and mandatory access controls. Primary script unknown suggests a missing or inaccessible mapped script; compare paths in both processes. For a timeout, inspect queue length, worker occupancy and application dependencies before increasing limits.
ss -ltn | grep ":19029 "# Unix socket lane only; the TCP fixture does not create this path:# stat /run/bytemind-fpm/lab.sock# namei -l /run/bytemind-fpm/lab.sock# Inspect only the lab-owned log files.Set independent timeout and buffering boundaries
fastcgi_connect_timeout 2s;fastcgi_send_timeout 5s;fastcgi_read_timeout 5s;fastcgi_request_buffering on;fastcgi_buffering on;fastcgi_next_upstream off;The connect limit covers establishment of the upstream connection. Send and read limits apply between successive writes or reads, not to total application duration. Request buffering collects the body before forwarding it; response buffering can decouple PHP output from a slow client and may use temporary files. Turning buffering off may help a streaming route but changes resource use. This lab turns retries off to avoid accidental repetition. Align application deadlines and FPM termination settings rather than treating Nginx timeouts as a cancellation guarantee.
Cache only deliberately public output
# http context:fastcgi_cache_path run/public-cache keys_zone=public_php:1m max_size=10m inactive=5m;# In a reviewed public-only location:# fastcgi_cache public_php;# fastcgi_cache_key "$scheme|$host|$request_uri";# fastcgi_cache_valid 200 30s;# In private routes, including this lab:# fastcgi_cache off;FastCGI caching can avoid repeating expensive public PHP work. A cache key must distinguish representations; user-specific or authorization-dependent responses should stay uncached unless a carefully reviewed policy proves isolation. Cache bypass controls lookup while no-cache controls storage; private routes should disable caching outright. Respect origin headers, cookie and authorization policy. The fixture returns no-store and keeps FastCGI caching off. Do not enable a shared cache for a login, cart or account page just because it is slow.
Practice and next step
Given a refused TCP connection, a socket permission error and a missing script, write a separate first check for each. Then use the local fixture in an approved disposable environment. Next chapter compares deployment patterns for application frameworks.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
PHP-FPM socket troubleshooting
Diagnose upstream connectivity, permissions, script mapping, timeout and cache policy using synthetic evidence.
What should be checked first for connection refused?
What is the safe response to Unix socket permission denied?
What does fastcgi_read_timeout bound?
What does fastcgi_request_buffering on do?
Which route is appropriate for the lab cache policy?