2.8.12. 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.

  1. Openup PHP settings.
  2. In field "error_reporting" choose the ones you want error types and save the changes:
  3. 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.

  1. Turnon PHP error outputby selecting all error types.
  2. V PHP settings turnon "Enabling error_log" and save the changes:
  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.

Content