Turn off display errors using file "php.ini"

Turn off display errors using file "php.ini"

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

Stefan Bogdanescu

Founder & Senior Architect

Why display_errors = Off Isn't Enough to Silence PHP Errors

You have configured your php.ini file with the standard directives to suppress error output, yet a simple file_open() call for a missing file still triggers a visible stack trace. This is a common frustration for developers trying to secure their production environment. The issue isn't that you missed a configuration step; it's that you are conflating two distinct concepts: displaying errors and logging them.

When you set display_errors = Off in your php.ini, you are telling the PHP engine not to echo error messages directly to the browser. However, this directive does not prevent PHP from generating the error internally. If an error occurs while display_errors is off but log_errors is on (which is the default behavior), PHP will write the full error message—including file paths and line numbers—to the log file specified by error_log.

The reason you are still seeing errors in your browser despite these settings usually boils down to one of three scenarios:

  1. Configuration Override: You might be editing a system-wide php.ini that is overridden by a more specific configuration provided by your hosting provider or server environment (like .user.ini, php-fpm.d/, or an Apache mod_php configuration).
  2. Missing Logging Configuration: You have disabled display but haven't enabled logging, leaving you without a mechanism to debug the application in production.
  3. The "Open" Directive Trap: If you are trying to suppress errors for specific functions like file operations, simply setting global display settings is insufficient if the error handler hasn't been properly redefined to log instead of die.

To truly secure your application and stop those read-and-open error messages from appearing in production, you must ensure that PHP logs every error to a file rather than trying to hide them completely without a plan for debugging. The correct approach involves setting display_errors = Off alongside log_errors = On. You should also verify the path for error_log is writable and accessible by your web server user.

Consider the following configuration block in your php.ini:

; Ensure errors are never sent to the browser
display_errors = Off
display_startup_errors = Off

; Capture all errors to a log file for debugging
log_errors = On
error_log = "/var/log/php_errors.log"

; Prevent HTML escaping of error messages (good practice)
html_errors = Off

There is a critical trade-off here: by turning off display_errors, you risk losing visibility into critical failures if your logging setup fails. If the log file fills up, permissions become restrictive, or the disk runs out of space, your application might crash silently without any trace. Therefore, robust production setups often pair these PHP settings with a monitoring agent or a centralized logging system like ELK or CloudWatch to ensure you are alerted when errors occur.

If you are working within a Laravel application, the php.ini configuration is just one layer of defense. Laravel provides its own error handling mechanisms that can be more granular. You should check your config/app.php file for the APP_DEBUG environment variable. When set to true, Laravel will render detailed exception pages regardless of PHP settings. Conversely, setting APP_DEBUG to false ensures that a generic 500 error page is shown, which is safer for production.

Additionally, if you need to handle specific file operations like file_get_contents() or custom functions that might fail, you can wrap them in try-catch blocks using set_error_handler(). This allows you to define custom logic: log the error details to a database or send an email notification instead of relying solely on PHP's default behavior.

set_error_handler(function ($errno, $errstr, $errfile, $errline) {
    // Log to file or external service here
    error_log("[$errno] $errstr in $errfile on line $errline");
    
    // Optionally throw an exception instead of displaying it
    throw new Exception($errstr);
});

Remember that disabling error display is a security best practice, but only if you have a reliable logging strategy in place. Without logs, you are effectively flying blind, unable to diagnose why a file operation failed or which line caused a crash until the next incident report arrives. Always verify your php.ini directives take effect by running php --ini or checking the output of phpinfo() on your live server to ensure no other configuration files are overriding your changes.

Our network