Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

display_errors has no effect on PHP behind nginx and PHP-FPM

Errordisplay_errors = On in php.ini, but the page stays blank

Short answer

With nginx there is no web-server PHP setting. PHP-FPM decides. Check whether a pool file locks display_errors, whether you edited the php.ini that FPM reads (not the CLI one), and whether .user.ini is still cached. Also check that nginx is not replacing the error response with its own error page.

  • Applies to nginx 1.24, PHP 8.3 FPM, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask PHP itself which value it uses when served by FPM. Put this in a temporary file in the web root, open it in the browser, and delete it afterwards.

    <?php
    var_dump(ini_get('display_errors'), php_ini_loaded_file());
  2. 2Match what you see, then jump to its fix

    1. 1ini_get shows an empty string or 0 whatever you set in php.ini or with ini_set()A pool file locks the value with php_admin_value or php_admin_flagFix
    2. 2php -i shows display_errors On, but the browser test shows another value or another php.ini pathYou edited the php.ini the CLI reads, not the one FPM readsFix
    3. 3The setting works after a few minutes, or only after FPM restartsA .user.ini change is cachedFix
    4. 4A plain nginx 500 or custom page appears instead of the PHP error textnginx replaces the PHP error response with its own error pageFix

What does the error look like?

  • display_errors = On in php.ini, but the page stays blank
  • 500 Internal Server Error with no PHP message in the browser

Cause 1 of 4

A pool file locks the value with php_admin_value or php_admin_flag

1Check

Settings in the pool file override php.ini, and php_admin_value and php_admin_flag cannot be changed with ini_set().

grep -rn -E "php_(admin_)?(value|flag)\[(display_errors|error_log|log_errors)" /etc/php/8.3/fpm/pool.d/

2Fix

Change the line in the pool file, or delete it, and restart FPM. For a development server set display_errors on; leave it off in production and read the log instead.

; /etc/php/8.3/fpm/pool.d/www.conf
php_flag[display_errors] = on

sudo systemctl restart php8.3-fpm

3Verify

Reload the test file; ini_get now returns the new value.

curl -s http://localhost/info-test.php

Confirmed by php.net

Did this fix it?

Cause 2 of 4

You edited the php.ini the CLI reads, not the one FPM reads

1Check

PHP looks for a php-SAPI.ini file first and a php.ini after that, in the SAPI's own search path. The CLI and FPM are separate SAPIs and can load separate files.

php --ini
ls /etc/php/8.3/

2Fix

Edit the php.ini whose path php_ini_loaded_file() printed in the browser test, then restart FPM so it re-reads the file.

sudo nano /etc/php/8.3/fpm/php.ini
sudo systemctl restart php8.3-fpm

3Verify

Run the browser test again.

curl -s http://localhost/info-test.php

Confirmed by php.net

Did this fix it?

Cause 3 of 4

A .user.ini change is cached

1Check

PHP re-reads .user.ini files only every user_ini.cache_ttl seconds, 300 by default. The file works only with the CGI and FastCGI SAPIs, and only for settings that are not system level.

# in the browser test file
var_dump(ini_get('user_ini.cache_ttl'));

2Fix

Wait for the cache time, restart FPM, or lower user_ini.cache_ttl in php.ini for development.

; php.ini (FPM)
user_ini.cache_ttl = 5

3Verify

Change the value, wait five seconds, run the browser test.

curl -s http://localhost/info-test.php

Confirmed by php.net

Did this fix it?

Cause 4 of 4

nginx replaces the PHP error response with its own error page

1Check

With fastcgi_intercept_errors on, any FastCGI response with a code of 300 or more goes to nginx's error_page handling. A fatal error usually returns 500, so the PHP output is dropped.

sudo nginx -T 2>/dev/null | grep -n -E "fastcgi_intercept_errors|error_page"

2Fix

Turn the directive off in the PHP location while debugging, or read the error from the PHP error log instead.

location ~ \.php$ {
    fastcgi_intercept_errors off;
}

3Verify

Reload nginx and trigger the error again.

sudo nginx -t && sudo systemctl reload nginx

Confirmed by nginx.org

Did this fix it?

How do I stop it coming back?

  • In production keep display_errors off, set log_errors on and give error_log a file the FPM user can write.
  • Keep one test file that prints ini_get and php_ini_loaded_file for the FPM SAPI, and remove it after use.
  • Restart FPM after every php.ini or pool change.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

nginx gives up waiting for the app and returns 504

upstream timed out (110: Connection timed out) while reading response header from upstream

nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.

5 causes, each with a fix

Servers

Cookies from a PHP backend vanish behind an nginx proxy

Login works when you call the backend directly but fails through nginx

nginx forwards Set-Cookie headers from the backend unchanged, so lost cookies usually come from the cookie itself: a domain or path that does not match the public URL, or Secure and SameSite flags the browser rejects.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.