PHP error guide
502 Bad Gateway from PHP-FPM: meaning and fix
Error summary
Check the pool socket, service health, ownership, and logs on both sides. The front server cannot obtain a valid FastCGI response from FPM.
What it means
Check the pool socket, service health, ownership, and logs on both sides. The front server cannot obtain a valid FastCGI response from FPM.
What the error means
This message means that the front server cannot obtain a valid FastCGI response from FPM. The exact signature distinguishes 502 bad gateway from php-fpm from a generic application failure.
Why PHP produces it
The engine or service reports “502 Bad Gateway from PHP-FPM” because its required precondition was not met. Check the pool socket, service health, ownership, and logs on both sides.
PHP version notes
The 502 bad gateway from php-fpm wording here is based on Current PHP-FPM, Apache 2.4, or nginx; punctuation and exception class names can differ on older branches or vendor builds.
Most common causes
- The immediate input or configuration reaches the specific condition: the front server cannot obtain a valid FastCGI response from FPM
- The code path assumes the prerequisite for 502 bad gateway from php-fpm has already been satisfied.
- For 502 bad gateway from php-fpm, development and production differ in version, extension, permissions, paths, or service configuration.
- An earlier operation returned an unchecked value that is consumed by the line reporting 502 bad gateway from php-fpm.
Minimal examples
BAD — reproduces the problem
fastcgi_pass unix:/run/php/missing.sock;
FIXED — safer pattern
fastcgi_pass unix:/run/php/php-fpm.sock;
Step-by-step diagnosis
- Copy the complete “502 Bad Gateway” text and retain the first application stack frame.
- Reproduce 502 bad gateway from php-fpm in the same SAPI and environment listed for this page.
- Before changing 502 bad gateway from php-fpm, inspect the preceding value or directive and verify its type, path, version, and permissions.
- Apply the narrow correction—check the pool socket, service health, ownership, and logs on both sides—then repeat the original request once.
Fixes
Correct the failing prerequisite
Check the pool socket, service health, ownership, and logs on both sides
fastcgi_pass unix:/run/php/php-fpm.sock;
Fail explicitly at the boundary
Validate the condition before the operation that emits 502 bad gateway from php-fpm, and log a safe diagnostic without credentials or full production paths.
Common mistakes when fixing it
- Suppressing 502 bad gateway from php-fpm instead of correcting its upstream condition.
- Testing 502 bad gateway from php-fpm only with the CLI binary when the failing request runs under FPM or Apache.
- Changing a global setting for 502 bad gateway from php-fpm before confirming the site-specific effective configuration.
How to prevent it
- Add a focused test that exercises the boundary responsible for 502 bad gateway from php-fpm.
- Keep runtime versions, extensions, configuration, and deploy artifacts affecting 502 bad gateway from php-fpm reproducible.
- Validate external data and service return values before they can trigger 502 bad gateway from php-fpm.
Web server / environment notes
fpm, linux. The failure occurs where the front server cannot obtain a valid FastCGI response from FPM
Tags: fpm,linux