Display and log errors for PHP
Written by James RichardsonBy default, InMotion disabled PHP error logging on all servers. In order for customers to troubleshoot their PHP code, PHP errors can be enabled to display and log errors using their local php.ini file or ini_set() in a specific PHP file. This article will cover how to turn display errors On and Off, error reporting settings, error logging, and the ini_set() function for individual error checking on specific pages.
Editing the php.ini to display errors
The php.ini by default should have the errors enabled; however, for the production environment, errors can be turned off. Sometimes when developing PHP scripts you may want to turn specific errors Off or On. Displaying errors is typically turned-off for production and Enabled for development. Displaying errors is disabled for production to protect sensitive information and not interfere with the format of the pages. This section will explain how to turn error reporting On and Off.
- Login into your cPanel.
- Go to the File Manager. Select the public_html directory and click Go.
Find the "Error handling and logging" section in the php.ini. You can enable the error_reporting by removing the ( ; ) from in front to the line. You can disable error_reporting by adding a ( ; ) in front of the line and add "error_reporting = none". See the following.
Error reporting set to server default.
; - Show all errors, except for notices ; ;error_reporting = E_ALL & ~E_NOTICE ;
Error reporting set to specifically report all errors.
; - Show all errors, except for notices ; error_reporting = E_ALL & ~E_NOTICE ;
Next you can set the display_errors to On or Off to either show the errors on your website or not. Look for the display_errors line in the php.ini and set it to On to display errors or Off to turn errors off. The code looks like the following.
display_errors = On
Php.ini error reporting settings
PHP has a list of different error reporting settings within the php.ini file itself. For example if you just want to display warnings only you can change the error_reporting to the following.
error_reporting = E_WARNING
The following table was created from the settings found in a standard php.ini file. The following table shows the available options.
| List of available options taken from php.ini | |
|---|---|
| E_ALL | All errors and warnings |
| E_ERROR | fatal run-time errors |
| E_WARNING | run-time warnings (non-fatal errors) |
| E_PARSE | compile-time parse errors |
| E_NOTICE | run-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_ERROR | fatal errors that occur during PHP's initial startup |
| E_CORE_WARNING | warnings (non-fatal errors) that occur during PHP's initial startup |
| E_COMPILE_ERROR | fatal compile-time errors |
| E_COMPILE_WARNING | compile-time warnings (non-fatal errors) |
| E_USER_ERROR | user-generated error message |
| E_USER_WARNING | user-generated warning message |
| E_USER_NOTICE | user-generated notice message |
Turning Error logging on
By default errors are set to error_log is set to /dev/null which means, it won't have error logging on. When errors are turned on will be stored 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 in the index.php file of that location, the error log will be stored in that folder. You can specify in the php.ini what file to store all errors in.
Important!You can 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 beyond.
<IfModule mod_suphp.c> suPHP_ConfigPath /home/USERNAME/public_html </IfModule>
For more information on suPHP please see our article on Choosing the best PHP handler.
- Login 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 the error_log for all your to a specific path on the server or leave the log.
This will place the error_log in the directory the error occurs in
; Log errors to specified file. error_log = error_log
This s will place all errors in the error log inside the public_html
; Log errors to specified file. error_log = /home/userna5/public_html/error_log
Now your errors will all be stored in the error_log in the public_html.
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 to with the error_reporting variable in it to allows error checking for that particular page. Below are the steps on how to do this.
- Login into your cPanel.
- Go to the File Manager. Select the public_html directory and click Go. If error logging is off in php.ini you can place this in a page for errors specific to this page Place the following
- Navigate to the PHP file you want to check errors for.
Open the file in the code editor.
- In the page, add the following to the top of the page.
ini_set('display_errors', '1');1 = On
0 = OffSave the page.
Now your PHP page only will display errors.
Latest Questions
Need more Help?
Search
Ask the Community!
Current Customers
| Chat: | Click to Chat Now | E-mail: | support@InMotionHosting.com |
|---|---|---|---|
| Call: | 888-321-HOST (4678) | Ticket: | Submit a Support Ticket |

