PHP FPM returns HTTP 500 for all PHP errors

PHP FPM returns HTTP 500 for all PHP errors

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

PHP FPM returns HTTP 500 for all PHP errors

When you configure Nginx to proxy requests to PHP-FPM, a critical boundary exists between the web server and the application logic. If your PHP script contains a syntax error or a fatal exception, you might expect a detailed stack trace in the browser. Instead, most setups default to returning a generic 500 Internal Server Error. This behavior isn't a mystery; it is the result of how PHP-FPM handles uncaught exceptions and how Nginx interprets the response from the FastCGI socket.

By default, PHP-FPM does not output errors directly to the browser when running in production mode. When an error occurs—such as the syntax mistake in your echo statement—it triggers a fatal exception. Unless explicitly told otherwise, PHP-FPM catches this exception and returns a plain text response containing only the phrase "Fatal error" followed by the error message, but often without the full context or source code location depending on configuration. More importantly, if display_errors is disabled (which is standard for production), PHP-FPM suppresses the output entirely to prevent leaking sensitive stack traces to the client.

To understand why you are seeing a 500 error specifically, you must look at how Nginx interacts with this suppressed output. When PHP-FPM encounters a fatal error while display_errors is off, it often sends an HTTP status code of 500 back to Nginx as part of the FastCGI response header, even if no body content is sent. Nginx respects this upstream status code and passes it directly to the client. Consequently, your browser sees a blank page or a generic error banner, but the actual reason—the syntax error in your PHP file—is hidden inside the logs of the backend process manager (like systemd) or the PHP log files.

The immediate fix involves two configuration layers: the PHP settings and the Nginx directives.

First, modify your PHP configuration to control error visibility. You can do this by editing the php.ini file located in your PHP installation directory (often found at /etc/php/8.x/fpm/php.ini). Locate the following lines:

display_errors = On
error_reporting = E_ALL

Setting display_errors to On forces PHP-FPM to echo the error message directly into the response body. This is useful for debugging, but it comes with a significant trade-off: you will now see stack traces in production if your application throws exceptions. If security is a concern, this should be done only during active development or behind a staging environment that is not exposed to the public internet.

Second, ensure that Nginx is configured to forward error logs correctly so you can monitor issues even when display_errors is eventually turned off for production. Your current Nginx configuration snippet looks mostly correct:

location ~ \.php$ {
    set $php_root /home/me/www;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;
}

However, you are missing the crucial directive for error logging at the server or location level. You should add fastcgi_param directives to point to your log files:

fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
fastcgi_param  DOCUMENT_ROOT     $php_root;
fastcgi_param  SERVER_NAME       $host;
fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;

# Ensure errors are logged, not just returned as 500 silently
error_log /var/log/nginx/error.log;

Additionally, verify that the PHP-FPM pool configuration (/etc/php/8.x/fpm/pool.d/www.conf) has a valid log_file path set. If this is empty or points to a non-existent directory, PHP-FPM cannot write error details to disk, leaving you with only the HTTP 500 response from Nginx.

A common pitfall is assuming that error_reporting(-1) in your PHP code overrides the server configuration. While setting error_reporting to -1 (which equals E_ALL | E_STRICT) ensures all errors are caught, the actual visibility still depends on the display_errors directive. If display_errors remains Off, PHP will log the error but suppress the HTML output, resulting in a 500 status code being returned by Nginx based on the FastCGI upstream response headers.

If you decide to keep display_errors disabled for production, ensure your application uses proper logging frameworks like Monolog or Laravel's logging system. These tools write stack traces to disk files rather than the browser, maintaining security while providing the debug information you need. For example, if you are using Laravel, their built-in error handling mechanisms automatically redirect exceptions to a log file and display a user-friendly page unless APP_DEBUG is true, which aligns with best practices for securing PHP-FPM deployments.

Ultimately, the HTTP 500 response is Nginx faithfully reporting what it received from PHP-FPM. By adjusting display_errors to On for debugging or ensuring your logging stack captures the output when display_errors is Off, you regain visibility into exactly why your script failed without compromising production stability.

Our network