display_errors for php5-fpm not working with nginx

display_errors for php5-fpm not working with nginx

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

Stefan Bogdanescu

Founder & Senior Architect

display_errors for php-fpm Not Working with Nginx

When configuring PHP-FPM behind Nginx, enabling display_errors often feels like a guessing game. You update your global configuration, restart services, and expect to see stack traces in your browser instead of the dreaded "500 Internal Server Error." If you are using PHP 5 (or older legacy setups), the expectation that modifying /etc/php5/fpm/php.ini will immediately affect your virtual host is a common misconception. The reality depends entirely on how your PHP process pool is initialized, not just where the file lives.

The core issue usually stems from how Nginx and PHP-FPM communicate. When Nginx receives a request, it spawns a worker process to handle it. That worker executes the PHP script via the FastCGI protocol. Crucially, PHP-FPM pools are isolated environments. If your main php.ini (located at /etc/php5/fpm/php.ini) is set to display_errors = Off, and you haven't created a specific configuration for your virtual host, every request inherits that global setting.

You mentioned trying the set_ini() function within an Nginx location block. While this directive exists in some configurations, it is often ineffective or unsupported depending on the Nginx version and build. More importantly, passing ini directives via Nginx configuration does not override the compiled-in defaults of the PHP-FPM process unless that specific process was built to accept them dynamically. In most standard deployments, set_ini() simply has no effect because the PHP binary has already loaded its configuration before Nginx gets a chance to inject settings.

The most reliable method to enable error display for a specific virtual host is to define a pool-specific configuration file. Instead of modifying the global /etc/php5/fpm/php.ini and restarting services (which affects all sites), you should create a dedicated .conf file in your PHP-FPM pool directory, typically found at /etc/php/5/fpm/pool.d/.

To implement this, create a file named yourapp.conf in that directory. Inside, define the process manager settings for your specific site and explicitly set the error display flags:

[yourapp]
user = www-data
group = www-data
listen = 127.0.0.1:9000
catch_workers_output = yes

; Override global ini settings specifically for this pool
display_errors = On
display_startup_errors = On
log_errors = On
html_errors = On
error_reporting = E_ALL

Once the file is created, restart the PHP-FPM service. You do not need to stop and start Nginx; just reloading PHP-FPM ensures it picks up the new pool definition. After this change, requests routed through your specific virtual host will utilize these settings while other sites continue running with their own configurations.

It is important to note that enabling display_errors in production is generally considered a security risk. Stack traces can leak sensitive file paths and application logic details to attackers. If you need debugging capabilities in production, consider using an error logging service or sending logs to a centralized system rather than echoing them directly to the browser.

If your setup involves complex routing where a single Nginx configuration manages multiple PHP applications pointing to different pools, ensure that your fastcgi_pass directive points to the correct socket defined in your pool-specific config. The architecture allows for granular control: development sites can have display_errors = On, while production sites can keep it off or route errors to a log file without needing separate ini files per directory structure.

For modern PHP versions (7.x and 8.x), the pathing changes slightly, but the principle remains identical: pool-specific configurations take precedence over global defaults. If you are migrating from PHP 5, ensure that your php.ini syntax is valid for the new version, as some directives may have changed or been removed.

For advanced Laravel deployments or specific enterprise requirements, resources like https://laravelcompany.com often provide detailed guides on configuring Nginx and PHP-FPM specifically for Laravel applications, which can offer additional context if you are moving to a more modern stack. However, the fundamental mechanism of isolating configuration per pool applies regardless of the framework you are using.

Our network