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.)
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
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
.htaccessfiles 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 </VirtualHost>
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.