Why display_errors = On Doesn't Work in Production Environments
When you configure a PHP environment, setting display_errors = On and error_reporting = E_ALL | E_STRICT in php.ini seems like a straightforward fix for debugging issues. However, if your application remains silent despite these settings, the culprit is almost certainly not the core PHP configuration but rather how Apache serves those requests.
In many modern web stacks, especially when using virtual hosts, Apache overrides the default error handling logic defined in the main php.ini. Instead of relying on the global directive, you need to ensure that Apache itself is configured to pass control back to PHP for error display. Without this bridge, errors are often suppressed or logged silently to the server's access logs instead of being rendered in the browser.
The Virtual Host Configuration Gap
The most common reason display_errors appears ineffective is that the specific virtual host configuration is not inheriting or applying the correct directives. In Apache2, global settings in /etc/php5/apache2/php.ini apply to the default server context, but custom domains often run under their own configuration blocks.
To resolve this, you must explicitly enable error display within the virtual host definition. You can do this by adding a .htaccess file or updating the VirtualHost block directly. If your setup allows access to .htaccess, place the following directive in the root directory of your project:
<IfModule mod_php5.c>
php_flag display_errors On
php_flag log_errors Off
</IfModule>
Alternatively, if you manage the VirtualHost block directly (e.g., /etc/apache2/sites-available/yourdomain.conf), add these lines inside the <VirtualHost> tags:
<IfModule mod_php5.c>
php_flag display_errors On
php_flag log_errors Off
</IfModule>
It is crucial to note that log_errors should generally remain Off when display_errors is active in a production-like environment, as logging the same error twice (to both output and the log file) can obscure the issue. However, if you are debugging an existing site where errors are crashing your application, keep log_errors On temporarily to capture the stack trace in /var/log/apache2/error.log.
Verifying the Actual Active Configuration
A frequent pitfall is assuming that editing the main php.ini affects your specific site. Apache often loads a separate configuration file for PHP modules. For PHP 5 on Ubuntu, this is typically located at /etc/php5/apache2/php.ini, but it might also be influenced by files in /etc/php5/conf.d/.
To verify which settings are actually active for your request, you can create a temporary phpinfo.php file with the following content:
<?php phpinfo(); ?>
Access this file via your browser. Scroll to the "error logging" section and inspect the values for display_errors, log_errors, and error_reporting. If these values do not reflect your changes, Apache is likely using a different configuration file or the .htaccess overrides are being blocked by an AllowOverride None directive in the main server config.
Maximizing Error Reporting in PHP 5.3
Regarding your question on strictness for PHP 5.3: The combination of E_ALL | E_STRICT is indeed the most comprehensive setting available within that version's scope. It captures all standard errors, warnings, notices, and user-level alerts, while also including "Strict" coding standards violations that warn about future incompatibilities or bad practices.
However, relying solely on this flag has limitations. E_STRICT was primarily designed for development environments to enforce coding conventions rather than catch runtime bugs in production code. In a live environment, displaying these errors can expose internal logic and file paths to attackers if your application is vulnerable.
Therefore, the best practice for future-proofing code while maintaining security is:
- Use
E_ALL | E_STRICTduring development withdisplay_errors On. - Switch to
E_ALL & ~E_DEPRECATEDin production, even if you have upgraded PHP versions, to ignore deprecated features that aren't yet removed but warn about potential breakage. - Always ensure
display_errorsis turned off in production environments, regardless of the reporting level, and rely on logging mechanisms instead.
The transition from PHP 5 to modern versions (PHP 7, 8, etc.) has significantly improved error handling and security defaults. While PHP 5.3 offers E_ALL | E_STRICT, newer versions provide better exception handling and stricter type checking out of the box, making them inherently safer for deployment without sacrificing visibility into errors during the debugging phase.
