Here we will cover how to display and log PHP errors to assist in debugging PHP applications or websites that use PHP to function, such as WordPress.
These steps can be used when dealing with an HTTP 500 error or a blank page on the site. By following the steps below, we can generate an actual error message which will help with the troubleshooting process.
Related Articles
Enable and Configure Debugging for WordPress
White Screen/500 HTTP Error on WordPress Website
Enable Debugging for PrestaShop
Enable Joomla Debug & Error Reporting
Enabling Error Reporting and Error Logging for the Website
- Log into cPanel
- Look for the MultiPHP INI Editor in the Software section
- If the MultiPHP INI Editor is available, click on it
- Choose the domain you want to make the changes to
- Find the display_errors line and toggle the slider on the right to enable or disable it
- Click Apply on the bottom
- Choose the domain you want to make the changes to
- If the MultiPHP INI Editor is not available, the steps can be done through File Manager
- Open File Manager in the Files section
- Navigate to the website's document root
- Look for a php.ini or .user.ini file in the document root of the domain
TIP: If one of these files exists in a different folder, you can copy it into the main document root folder. If you can't find any of these files, a new php.ini file can be created. - Edit the file
- Insert the following code into the file to enable error displaying and error logging
display_errors = On
REPLACE: FILEPATH HERE with the website's document root.
error_log = FILEPATH HERE/error_log
log_errors = On
error_reporting = E_ALL
display_errors = On
will enable the setting to display errors on the front page of the websiteerror_log = FILEPATH HERE/error_log
will direct the website to the file to log PHP errors tolog_errors = On
will enable PHP error loggingerror_reporting = E_ALL
will ensure that all PHP errors are included
- Click Save Changes
- To be sure that these changes take effect for not only the current directory, but all subdirectories, you'll want to make your php.ini file recursive
- After setting the site to display errors, reload the page to look for any errors being displayed
- If no errors appear, download or view the error_log file to see if any errors have been logged
- If no error_log file exists, it's likely that there are no PHP errors on the site
- If no errors appear, download or view the error_log file to see if any errors have been logged
- Open File Manager in the Files section
Enable display_errors within PHP
- You can also enable display_errors by editing PHP code directly
- Insert the following code to the top of a relevant PHP file
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
- Insert the following code to the top of a relevant PHP file