In this tutorial:

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

  1. Login into your cPanel.
  2. Go to the File Manager. Select the public_html directory and click Go.
  3. Report all PHP errorsFind 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
    ;
    

  4. Display PHP errors OnNext 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

List of PHP Error reporting settingsPHP 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>
The IfModule makes Apache 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 please see our article on Choosing the best PHP handler.

  1. Login into your cPanel.
  2. Go to the File Manager. Select the public_html directory and click Go.
  3. Log PHP errors OnYou can set the following line of code to On to log errors or off to turn error logging off.
    log_errors = On
    

  4. Path to PHP Error logNext 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.

  1. Login into your cPanel.
  2. Go to the File Manager. Select the public_html directory and click Go.
  3. If error logging is off in php.ini you can place this in a page for errors specific to this page Place the following
  4. Navigate to the PHP file you want to check errors for.

    Open the file in the code editor.

  5. In the page, add the following to the top of the page.
    ini_set('display_errors', '1');

    1 = On
    0 = Off

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

Did you find this article helpful?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve our Support Center:
Email Address
Optional, but our team may contact you for more information.
Like this Article?

Post a Comment

Name:
Email Address:
Comment:
Are you a bot?
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

Write New!
Do you want to publish a tutorial to our support center?

News / Announcements

SSL Certficate Warnings
Updated 2014-04-14 11:34 am EST
Hits: 2219
Heartbleed 0-day OpenSSL security bug
Updated 2014-04-14 04:43 pm EST
Hits: 5641

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!