PHP display_errors Explained: Configuration, Debugging, and Best Practices
Introduction
The display_errors directive controls whether PHP displays error messages directly in the browser. It is an important configuration option for debugging applications during development, but it should be used carefully on production servers.
Displaying detailed error messages can help developers quickly identify problems. However, exposing internal paths, database information, or application details to visitors may introduce security risks.
This guide explains how display_errors works, how to configure it, recommended settings for different environments, and common troubleshooting scenarios.
Test Environment
What Is display_errors?
The display_errors directive determines whether PHP sends error messages to the browser.
Example:
display_errors = On
With this setting enabled, PHP displays runtime errors, warnings, and notices directly in the page output.
To disable error display:
display_errors = Off
Errors are no longer shown to visitors, although they can still be written to log files if error logging is enabled.
How display_errors Works
When display_errors is enabled, errors are visible in the browser. When disabled, users see only the application response, while administrators can review the logs.
Check the Current Value
Run:
Example:
display_errors => Off => Off
Or verify using:
Search for:
display_errors
Locate the Active php.ini File
Example:
Loaded Configuration File: /etc/php.ini
If you are using PHP-FPM, ensure you modify the configuration used by the web server.
Enable display_errors
Open the PHP configuration file.
Find:
display_errors = Off
Enable it:
display_errors = On
Save the file.
Restart PHP-FPM
Apply the configuration.
Verify:
Expected output:
Active: active (running)
Development vs Production
Development Environment
Recommended:
Displaying errors makes debugging faster and helps identify syntax errors, warnings, and exceptions.
Production Environment
Recommended:
Users should never see internal PHP error messages.
Instead, errors should be recorded in log files for later analysis.
display_errors vs log_errors
These directives serve different purposes.
Many production servers use:
This configuration protects sensitive information while preserving useful diagnostic data.
Common Issues
Blank White Page
If the page is completely blank, temporarily enable:
display_errors = On
This often reveals the underlying PHP error.
Remember to disable it again after debugging.
Changes Have No Effect
Possible causes include:
PHP-FPM was not restarted.
The wrong php.ini file was modified.
The application overrides the setting at runtime.
Error Messages Still Do Not Appear
The application may suppress errors using:
or the server may have additional configuration that affects error reporting.
Security Considerations
Displaying errors on a production website may reveal:
File system paths
Database queries
Framework structure
Configuration details
Installed software versions
This information can help attackers understand the application's internal structure.
For public-facing websites, keeping display_errors disabled is considered a security best practice.
Best Practices
Enable display_errors only during development.
Keep display_errors = Off on production servers.
Enable log_errors to preserve diagnostic information.
Restart PHP-FPM after changing configuration values.
Verify the setting using phpinfo() or php -i.
Conclusion
The display_errors directive controls whether PHP displays runtime errors directly in the browser. While enabling it can simplify debugging during development, it should generally remain disabled on production servers to avoid exposing sensitive information.
A common production configuration is to disable error display while enabling error logging, providing a balance between security and effective troubleshooting.
Explore More
› PHP opcache.max_accelerated_files Explained: Configuration, Performance, and Best Practices
› PHP opcache.validate_timestamps Explained: Configuration, Code Updates, and Best Practices
› PHP opcache.revalidate_freq Explained: Configuration, Performance, and Best Practices
› PHP opcache.enable Explained: Configuration, Performance, and Best Practices