PHP Error Reporting: Enable, Display, and Log Errors
PHP error reporting controls which errors are shown, logged, or silently ignored. Configuring it correctly is essential during development — where you want full visibility — and on production servers — where errors should be logged but never displayed to users.
This guide explains how to configure PHP error reporting using php.ini, the error_reporting() function, and .htaccess. If you are not sure which PHP version is active, first check it with the PHP version guide
.
Quick Reference
| Task | Setting / Command |
|---|---|
| Enable all errors in php.ini | error_reporting = E_ALL |
| Display errors on screen | display_errors = On |
| Hide errors from users (production) | display_errors = Off |
| Log errors to a file | log_errors = On |
| Set custom log file | error_log = /var/log/php/error.log |
| Enable all errors at runtime | error_reporting(E_ALL); |
| Suppress all errors at runtime | error_reporting(0); |
PHP Error Levels
PHP categorizes errors into levels. Each level has a name (constant) and a numeric value. You can combine levels using bitwise operators to control exactly which errors are reported.
The most commonly used levels are:
-
E_ERROR— fatal errors that stop script execution (undefined function, missing module) -
E_WARNING— non-fatal errors that allow execution to continue (wrong function argument, missing include) -
E_PARSE— syntax errors detected at parse time; always stop execution -
E_NOTICE— minor issues such as using an undefined variable; useful during development -
E_DEPRECATED— warnings about features that will be removed in future PHP versions -
E_ALL— all errors and warnings; recommended during development
For a full list of error constants, see the PHP error constants documentation .
Configure Error Reporting in php.ini
The php.ini file is the main configuration file for PHP. Changes here apply globally to all PHP scripts on the server. After editing php.ini, restart the web server for the changes to take effect.
To find the location of your active php.ini file, run:
php --iniEnable Error Reporting
Open php.ini and set the following directives:
; Report all errors
error_reporting = E_ALL
; Display errors on the page (development only)
display_errors = On
; Display startup sequence errors
display_startup_errors = Ondisplay_errors on a production server. Displaying error messages to users exposes file paths, database credentials, and application logic that can be exploited.Log Errors to a File
To write errors to a log file instead of displaying them, set:
; Disable displaying errors
display_errors = Off
; Enable error logging
log_errors = On
; Set the path to the log file
error_log = /var/log/php/error.logMake sure the directory exists and is writable by the web server user. To create the directory:
sudo mkdir -p /var/log/php
sudo chown www-data:www-data /var/log/phpRecommended Development Configuration
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
error_log = /var/log/php/error.logRecommended Production Configuration
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /var/log/php/error.logThis reports all serious errors while suppressing deprecation notices, and logs everything without displaying anything to users.
Configure Error Reporting at Runtime
You can override php.ini settings within a PHP script using the error_reporting() function and ini_set(). Runtime changes apply only to the current script.
To enable all errors at the top of a script:
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);To report all errors except notices:
<?php
error_reporting(E_ALL & ~E_NOTICE);To suppress all error output (not recommended for debugging):
<?php
error_reporting(0);Runtime configuration is useful during development when you do not have access to php.ini, but it should not replace proper server-level configuration on production systems.
Configure Error Reporting in .htaccess
If you are on a shared hosting environment without access to php.ini, you can configure PHP error reporting via .htaccess (when PHP runs as an Apache module):
php_flag display_errors On
php_value error_reporting -1
php_flag log_errors On
php_value error_log /var/log/php/error.logUsing -1 for error_reporting enables all possible errors, including those added in future PHP versions.
.htaccess directives only work when PHP runs as an Apache module (mod_php). They have no effect with PHP-FPM.View PHP Error Logs
Once log_errors is enabled, errors are written to the file specified by error_log. To monitor the log in real time, use the tail -f
command:
tail -f /var/log/php/error.logIf no error_log path is set, PHP writes errors to the web server error log:
- Apache:
/var/log/apache2/error.log - Nginx + PHP-FPM:
/var/log/nginx/error.logand/var/log/php/php-fpm.log
For related service commands, see how to start, stop, or restart Apache and how to start, stop, or restart Nginx .
Troubleshooting
Errors are not displayed even with display_errors = On
Confirm you are editing the correct php.ini file. Run php --ini or call phpinfo() in a script to see which configuration file is loaded and the current value of display_errors.
Changes to php.ini have no effect
The web server must be restarted after editing php.ini. For Apache, run sudo systemctl restart apache2. For Nginx + PHP-FPM, restart Nginx and your versioned PHP-FPM service (for example, sudo systemctl restart nginx php8.3-fpm).
No errors appear in the log file
Check that the log file path is writable by the web server user (www-data or nginx), and that log_errors = On is set in the active php.ini.
ini_set('display_errors', '1') has no effect
Fatal parse errors (E_PARSE) occur before any PHP code runs, so ini_set() cannot catch them. Enable display_errors in php.ini or .htaccess to see parse errors.
Error suppression operator @ hides errors
PHP’s @ prefix suppresses errors for a single expression. If errors from a specific function are missing from logs, check whether the call is prefixed with @.
FAQ
What is the difference between display_errors and log_errors?display_errors controls whether errors are output directly to the browser or CLI. log_errors controls whether errors are written to the error log file. On production, always set display_errors = Off and log_errors = On.
Which error_reporting level should I use?
Use E_ALL during development to catch every possible issue. On production, use E_ALL & ~E_DEPRECATED to log serious errors while suppressing deprecation notices that do not require immediate action.
How do I check the current error reporting level?
Call error_reporting() with no arguments: it returns the current bitmask as an integer. You can also check it in the output of phpinfo().
Can I log errors to a database instead of a file?
Not directly via php.ini. Use a custom error handler registered with set_error_handler() and set_exception_handler() to send errors to a database, email, or external logging service.
Where is php.ini located?
Run php --ini from the command line or add <?php phpinfo(); ?> to a script and load it in a browser. The “Loaded Configuration File” row shows the active path. Common locations are /etc/php/8.x/cli/php.ini (CLI) and /etc/php/8.x/apache2/php.ini (Apache).
Conclusion
During development, set error_reporting = E_ALL and display_errors = On in php.ini to see all errors immediately. On production, set display_errors = Off and log_errors = On to log errors silently without exposing details to users.
Make changes in php.ini for permanent server-wide configuration, use error_reporting() and ini_set() for per-script overrides, or use .htaccess on shared hosting without php.ini access.
If you have any questions, feel free to leave a comment below.




















