PHP Error Reporting and Logging Configuration

PHP Error Reporting and Logging Configuration

Last updated:

Error reporting and logging is an important part of application development. It's not always easy to set these up in PHP due to there being a lot of configuration directives that affect the way errors are shown or logged.

These are a few common use cases that come up during an application's life cycle. I've included the relevant php.ini directives.

(specific values, such as the location where I store log files, are only provided as an example.)

Production setup

You want to log errors, but you don't want users to see them (due to security issues). Example for php.ini:

display_errors = Off
error_reporting = E_ALL & ~E_DEPRECATED
display_startup_errors = Off
log_errors = On
error_log = /tmp/phplog.log

Development setup

You want to log errors and show them on the screen as well. Example for php.ini:

display_error = On
error_reporting = E_ALL & ~E_DEPRECATED
display_startup_errors = On
log_errors = On
error_log = /tmp/phplog.log


  • Note that these settings can also be set in .htaccess files or in Apache VHost definition files (using the directive php_value). (Note that php constants have been replaced by integers here). For example (on a VirtualHost definition file):

    # dev setup
    <VirtualHost *:80>
        DocumentRoot /var/www/my-website
        php_flag display_startup_errors on
        php_flag display_errors on
        php_flag html_errors on
        php_flag  log_errors on
        php_value error_log  /tmp/phplog.log
        php_value error_reporting 6135
  • error_reporting controls the logs that get logged or shown in the screen. Even if you have enabled logging and error display, nothing will get seen and/or logged if you have incorrect error_reporting settings.

Extra resources

Dialogue & Discussion