2.8.13. Outputting and logging PHP errors

PHP errors can display directly on the site or commit them to the log for further analysis.

Depending on the internal structure of the site and the type of problem encountered, the output or logging of PHP errors may not always help to identify the causes of problems on the site. In some cases, it may be more useful to enable debugging mode using the tools of the site itself (as, for example, in WordPress, Joomla!, PrestaShop) or manual addition of debugging directives by a developer or a specialized specialist to his code, allowing you to track at what stage and for what reason an error occurs.

The PHP parameter is responsible for the types of displayed errors. error_reporting.

To customize the error output, do the following:

  1. Openup PHP settings.
  2. Against "error_reporting" check the boxes next to the ones you want values:
  3. Save your changes.
  4. Wait approximately 10-15 minutes for the changes to take effect.

PHP errors can be logged in different ways — both by hosting tools and at the level of site scripts.

To set up PHP error logging, do the following:
  1. Turnon PHP error outputby checking the boxes opposite the required error types.
  2. At the bottom of the page with PHP settings check the box next to "Enabling error_log" and press "Save":
  3. Wait approximately 10-15 minutes for the changes to take effect.
  4. Reproduce the error on the site and check the entries in PHP error log.
If you need to capture PHP errors in a separate file, this can be done at the level of the scripts themselves. For example, add the following code at the beginning of the very first script to run:
ini_set("log_errors", 1);
ini_set("error_log", "/path/to/logu/php-error.log");

As a result, if a PHP error occurs during the operation of this script, it will be written to the log at the specified path.