cPanelResources

Tutorial Adjusting PHP Logging Levels To Troubleshoot PHP Script Errors

Changing PHP error settings

Sometimes your site might not function as expected, or it may display errors or warnings. Changing PHP error handling will help deduce functionality issues and prevent unwanted information on your site.

Regardless of the PHP handler in use, you can edit PHP settings the MultiPHP INI Editor in WHM or cPanel. PHP will display and log all errors except for Notices. It also prevents errors from being displayed in the browser:
Code:
error_reporting = E_ALL & ~E_NOTICE
log_errors = On
display_errors = Off
While Notices are generally not the source of site level issues, they may help narrow down the root cause.

To change this setting at the global level, login to WHM and navigate to the MultiPHP INI Editor. In the Editor Mode tab, select the PHP version you need to change:
WHM_MultiPHP_INI_Editor.png

Next, search for error_reporting in the text editor, change the line to the following, and click Save:
Code:
error_reporting = E_ALL
To change this setting for a domain, click the MultiPHP INI Editor icon in the domain's cPanel account. In the Editor Mode tab, select your domain from the Select a location dropdown. Add the error_reporting setting with the value of E_ALL and click Save:
Code:
error_reporting = E_ALL
While constants are the most common method, the directive can also take integers as a setting. Below is the list of integers and their named constants:
Code:
1      E_ERROR
2      E_WARNING
4      E_PARSE
8      E_NOTICE
16     E_CORE_ERROR
32     E_CORE_WARNING
64     E_COMPILE_ERROR
128    E_COMPILE_WARNING
256    E_USER_ERROR
512    E_USER_WARNING
1024   E_USER_NOTICE
2048   E_STRICT
4096   E_RECOVERABLE_ERROR
8192   E_DEPRECATED
16384  E_USER_DEPRECATED
32767  E_ALL
This setting will report only USER and STRICT errors:
Code:
error_reporting = E_USER_ERROR & E_STRICT
PHP's official documentation has information about predefined constants and bitwise operators:

Predefined Constants
Bitwise Operators

Error log locations

When trying to troubleshoot site issues, it is beneficial to check for PHP errors. But, most people do not want to display the errors on their site. Displaying errors on a live site generally isn't a good user experience. In that case, reviewing the logs will help determine if PHP is the source of the issue. PHP saves errors to different logs based on the PHP handler:

PHP-FPM - /home/USERNAME/logs/domain_tld.php.error.log
CGI, DSO, FCGI, LSAPI - /var/log/apache2/error_log

The suPHP handler logs errors in the directory where the initial script runs. When accessing a WordPress site, PHP errors log to /home/USERNAME/public_html/error_log. When accessing your-site.tld/wp-admin, errors log to /home/USERNAME/public_html/wp-admin/error_log.

Common errors

There are different types of Fatal errors, of which these three are the most common:
Code:
PHP Fatal error:  require(): Failed opening required '/home/USERNAME/public_html/wp-includes/load.php' (include_path='.:/opt/cpanel/ea-php56/root/usr/share/pear') in /home/USERNAME/public_html/wp-settings.php on line 19

PHP Warning:  PHP Startup: Unable to load dynamic library '/opt/cpanel/ea-php56/root/usr/lib64/php/modules/memcached.so' - libmemcached.so.11: cannot open shared object file: No such file or directory in Unknown on line 0

PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 80 bytes) in /home/USERNAME/public_html/wp-includes/cache.php on line 506
Incorrect permissions or ownership generally cause the Failed opening required error. The file needs to accessible by the user that is running PHP. From a security standpoint, this should be the cPanel user.

Sites referencing non-existent extensions can cause the Unable to load dynamic library error. If the site requires an extension, you will need to install it using EasyApache 4 (WHM >> Home >> Software >> EasyApache 4). Otherwise, remove the extension reference in the script or configuration file.

The Allowed memory size error occurs when a PHP script requires more memory than PHP allows. The default limit is 32M and is often enough, but sometimes a site needs more. A good rule of thumb is to add the "tried to allocate" bytes to the memory_limit plus some extra. This action allows some wiggle room for the script.

Additional Questions / Feedback

Feel free to click on the Discussion tab to let us know if you have any questions or feedback about the information in this tutorial.
Author
cPanelResources
Views
4,610
First release
Last update
Rating
0.00 star(s) 0 ratings