PHP errors can appear in the web response for temporary debugging or stay hidden from visitors while diagnostics remain in the server's logs. Visible warnings and fatal errors shorten debugging when a request fails, an include breaks, or a runtime change stops the application from starting. Hiding that same output matters on internet-facing systems because diagnostics can expose stack traces, filesystem paths, SQL fragments, and other internal details that belong in operator logs instead of response bodies.

PHP separates which errors are raised from where those errors go. error_reporting chooses the severities, display_errors and display_startup_errors decide whether a client sees them, and log_errors keeps the same events available in the server log. The effective values can come from the main php.ini file, PHP-FPM pool directives, or per-directory .user.ini files.

The commands use the Ubuntu 26.04 php8.5-fpm service; Debian releases and third-party package sources may use another branch. Replace the sample 8.5 branch, service unit, document root, and URL with the runtime that serves the application, keep log_errors enabled whenever display is disabled, and test the PHP-FPM configuration before reload so an error-display change does not become an outage.

Steps to show or hide PHP errors on Linux:

  1. Create a temporary test script in the site's document root using your text editor.
    $ sudoedit /var/www/billing-portal/current/public/php-warning-check-c7f29e.php
    php-warning-check-c7f29e.php
    <?php
    echo PHP_SAPI, "\n";
    echo php_ini_loaded_file(), "\n";
    trigger_error('display probe', E_USER_WARNING);
    echo "probe complete\n";

    The script exposes runtime details to anyone who can reach it, so public sites need an unguessable file name or a restricted path until step 13 removes it.

  2. Request the script through the site's normal address.
    $ curl -s https://billing-portal.example.net/php-warning-check-c7f29e.php
    fpm-fcgi
    /etc/php/8.5/fpm/php.ini
    probe complete

    The first line names how PHP runs and the second names the php.ini file to edit. If the first line shows apache2handler, edit the Apache module configuration path instead of the PHP-FPM path.

  3. Back up the php.ini file before changing it.
    $ sudo cp /etc/php/8.5/fpm/php.ini /etc/php/8.5/fpm/php.ini.bak-before-error-display
  4. Set a temporary debugging profile in the php.ini file when warnings, notices, and startup failures must be visible in the response.
    $ sudoedit /etc/php/8.5/fpm/php.ini
    display_errors = On
    display_startup_errors = On
    error_reporting = E_ALL
    log_errors = On

    If errors only need to stay hidden, continue at step 8 with the production profile, because this debugging profile shows errors to every visitor.

    A .user.ini file in the document root or a php_admin_value line in the PHP-FPM pool file can override these values.

    On a public site, visitors can see error output with internal paths from the reload in step 6 until the production profile is reloaded in step 10.

  5. Test the PHP-FPM configuration before reloading the service.
    $ sudo php-fpm8.5 -t
    [06-Nov-2026 16:31:36] NOTICE: configuration file /etc/php/8.5/fpm/php-fpm.conf test is successful

    The binary name follows the installed branch, such as php-fpm, php-fpm8.4, or php-fpm8.5.

    Do not reload the service until the configuration test succeeds.

  6. Reload the runtime that serves the application so new requests use the updated directives.
    $ sudo systemctl reload php8.5-fpm

    Reload Apache instead, such as sudo systemctl reload apache2 or sudo systemctl reload httpd, when step 2 showed apache2handler.

  7. Request the script again to confirm that the debugging profile displays the warning.
    $ curl -s https://billing-portal.example.net/php-warning-check-c7f29e.php
    fpm-fcgi
    /etc/php/8.5/fpm/php.ini
    <br />
    <b>Warning</b>:  display probe in <b>/var/www/billing-portal/current/public/php-warning-check-c7f29e.php</b> on line <b>4</b><br />
    probe complete

    PHP formats the warning as HTML by default, so a browser shows the same line without the tags.

    Switch back to the production profile after the debugging session if the site is reachable by users.

  8. Set the production profile in the php.ini file so the response stays clean while the logs keep the diagnostics.
    $ sudoedit /etc/php/8.5/fpm/php.ini
    display_errors = Off
    display_startup_errors = Off
    error_reporting = E_ALL
    log_errors = On

    Keeping error_reporting = E_ALL with log_errors = On hides warnings from the client without discarding them from logs.

    Setting error_reporting = 0 suppresses diagnostics instead of only hiding them from the response.

  9. Test the PHP-FPM configuration again before reloading the service.
    $ sudo php-fpm8.5 -t
    [06-Nov-2026 16:31:36] NOTICE: configuration file /etc/php/8.5/fpm/php-fpm.conf test is successful
  10. Reload the runtime again so new requests use the production profile.
    $ sudo systemctl reload php8.5-fpm
  11. Request the script again to confirm that the production profile hides the warning from the response.
    $ curl -s https://billing-portal.example.net/php-warning-check-c7f29e.php
    fpm-fcgi
    /etc/php/8.5/fpm/php.ini
    probe complete
  12. Confirm that the hidden warning still reaches the web server's error log.
    $ sudo grep "display probe" /var/log/nginx/error.log
    ##### snipped #####
    2026/11/06 16:31:36 [error] 1036#1036: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  display probe in /var/www/billing-portal/current/public/php-warning-check-c7f29e.php on line 4" while reading response header from upstream, client: 127.0.0.1, server: billing-portal.example.net, request: "GET /php-warning-check-c7f29e.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.5-fpm.sock:", host: "billing-portal.example.net"

    Debian and Ubuntu packages pass the entry to the web server, shown here for Nginx. CentOS Stream packages write it to /var/log/php-fpm/www-error.log, and a host that sets error_log writes to that file or to syslog instead.

  13. Remove the temporary test script.
    $ sudo rm /var/www/billing-portal/current/public/php-warning-check-c7f29e.php

    Leaving the file in place exposes SAPI, configuration path, and error-display state to anyone who can reach the URL.

Share this guide