Error reporting in PHP

Posted on 21.03.07


Some way down the road the default php.ini started to get shipped with settings that stopped the error printing. The default location of this file is /usr/local/lib/php.ini, and the most common settings that controls the error reporting behaviour is listed below:

error_reporting = E_ALL | E_ERROR | ... | E_USER_NOTICE
display_errors = On | Off
log_errors = On | Off

First of all error_reporting decides what type of errors or messages that will be taken care of in the first place. See php.ini for details. Then you have the options to:

  1. Print the error as part of the HTML by setting display_errors to On
  2. Log the error to Apaches error_log by setting log_errors to On
  3. Or both print and log the errors and messages

There is a reason why they stopped to display errors as a default thing. This is because you are risking to leak sensitive information about your server configuration. A way to achive instant information about errors, and keep the rest of your web site safe, is to alter the settings for just the scripts you are working with at run time. It can be done like this:


Suggested readings:

Posted in: Uncategorized