How to Display and Log PHP Errors InMotion Hosting ContributorUpdated on September 28, 2022 6 Minute Read There are two methods for viewing PHP errors that occur while running your website. You can either display errors directly on your website (viewable from any web browser) or enable error logging to write the errors to a specified file (viewable inside a text file). This article will cover how to turn display_errors On and Off, adjust error reporting settings, configure error logging, and use the ini_set() function to help troubleshoot PHP errors with your website. Editing the php.ini to Display Errorsphp.ini Error Reporting SettingsTurning Error Logging OnUsing int_set() to Display ErrorsMaintain Your Log Files WARNING: These instructions were written for the EasyApache 3 PHP/Apache configuration. This older configuration efficiently handles direct modifications to the php.ini file. However, if you are running EasyApache 4, then cPanel/WHM is designed to maintain the php.ini file(s). Any changes made directly to the php.ini file (while using EA3) may cause this functionality to not perform as expected. Be sure to check which version of EasyApache you are running, prior to making modifications as outlined in this article. Editing the php.ini to Display Errors While your site is live, the php.ini file should have display_errors disabled for security reasons. However, for the development environment, display_errors can be enabled for troubleshooting. Displaying errors should be disabled while the site is live, to protect sensitive information and not interfere with the format of your website pages. When display_errors is On, your site’s pages will display any PHP errors encountered when loading your website in a browser. This section will explain how to control error reporting and turn display_errors On and Off. Log into your cPanel.Go to the File Manager. Select the home directory for your website (by default: public_html) and click Go.Find the “Error handling and logging” section in the php.ini. In order to display or log errors, you need to enable error_reporting by removing the ( ; ) from in front to the line. You can disable error_reporting by adding a ( ; ) in front of the line. Refer to the code below: Error reporting disabled: ; - Show all errors, except for notices ; ;error_reporting = E_ALL & ~E_NOTICE ; Error reporting enabled to specifically report all errors, but not notices: ; - Show all errors, except for notices ; error_reporting = E_ALL & ~E_NOTICE ; Next you can set the display_errors variable to On or Off to either show the errors on your website or not. Look for the display_errors line in the php.ini file and set it to On to display errors or Off to turn not display errors. The code looks like the following:Display errors:display_errors = On Do not display errors:display_errors = Off php.ini Error Reporting Settings PHP has a list of different error reporting settings within the php.ini file itself. For example, if you want to display only warnings you can change the error_reporting line to the following: error_reporting = E_WARNING The following table was created from the settings found in a standard php.ini file. Refer to the following table for the available options. List of available options taken from php.iniDescriptionE_ALLAll errors and warningsE_ERRORfatal run-time errorsE_WARNINGrun-time warnings (non-fatal errors)E_PARSEcompile-time parse errorsE_DEPRECATEDnotices for the use of functions that will be retired in a future versionE_NOTICErun-time notices (these are warnings which often result from a bug in your code, but it’s possible that it was intentional (e.g., using an uninitialized variable and relying on the fact it’s automatically initialized to an empty string)E_CORE_ERRORfatal errors that occur during PHP’s initial startupE_CORE_WARNINGwarnings (non-fatal errors) that occur during PHP’s initial startupE_COMPILE_ERRORfatal compile-time errorsE_COMPILE_WARNINGcompile-time warnings (non-fatal errors)E_USER_ERRORuser-generated error messageE_USER_WARNINGuser-generated warning messageE_USER_NOTICEuser-generated notice message Turning Error Logging On By default errors are written to the error_log, which is set to /dev/null. This means, error logging won’t occur. When errors are turned on, errors will be stored in a file in the directory the error occurs in. For example, if you have a PHP file called index.php in a subdirectory like public_html/wordpress, if you have any PHP errors while running that file’s scripts, the error log will be stored in that folder (public_html/wordpress). You can specify (in the php.ini) which file to store all errors in. Important! You must place the following code in the .htaccess to make the local php.ini work for the current directory where the .htaccess resides and all subdirectories within. <IfModule mod_suphp.c> suPHP_ConfigPath /home/USERNAME/public_html </IfModule> The IfModule causes Apache to load the directive only if suPHP is used, so the site doesn’t break if switched to another PHP handler such as DSO. For more information on suPHP and DSO please see our article on Choosing the best PHP handler. Log into your cPanel.Go to the File Manager. Select the public_html directory and click Go.You can set the following line of code to On to log errors or Off to turn error logging off. log_errors = On Next you can save errors from any page in your files to a specific location by specifying the error_log. The example below uses a file named error_log This will place the error_log in the directory the error occurs in: ; Log errors to specified file. error_log = error_log This will write all errors to the error_log file inside the public_html directory, regardless of what directory the errors were encountered in: ; Log errors to specified file. error_log = /home/userna5/public_html/error_log Using int_set() to Display Errors In the case you want errors to not display site wide and you want to check errors on a single page, you can use the ini_set() function to have errors displayed on a particular page. The basic syntax from php.net shows the function and its parameters is as follows: string ini_set ( string $varname , string $newvalue ) This can be placed at the top of your PHP page, with the error_reporting variable in it, to allow error checking for that particular page. Below are the steps for how to do this. Log into your cPanel.Go to the File Manager. Select the public_html directory and click Go.Navigate to the PHP file you want to check errors for. Open the file in the code editor.In the file, add the following at the top. ini_set('display_errors', '1'); 1 = On0 = OffSave the page. Now your PHP page only will display errors. Maintain Your Log Files Now that you have enabled error logging, be sure to maintain your log files. If you are getting errors regularly, be sure to remove the logs periodically. You may do so by just removing the file from within the File Manager or through any other method that you prefer to manage your files. A large log file can sometimes cause issues by possibly filling your disk space or if on shared hosting with unlimited disk space, begin to impact other customers on the server. Share this Article Related Articles Intro to Migrating your WordPress Site Data Migrating your WordPress Database Migrating WordPress Files Configuring WordPress After a Migration Testing your WordPress website after Migration How to Move WordPress from a Subfolder to the Root Directory What to expect during a mass server migration Move Your WordPress Site to a New Server Moving Websites Built with Older Technology into WordPress How to Export Your WordPress Sites