---
title: "How to Display and Log PHP Errors"
description: "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..."
url: https://www.inmotionhosting.com/support/website/troubleshoot-php-errors/
date: 2013-01-24
modified: 2022-09-28
author: "InMotion Hosting Contributor"
categories: ["Website", "Website Error Numbers"]
type: post
lang: en
---

# How to Display and Log PHP Errors

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 Errors](#editing_the_php_ini)
- [php.ini Error Reporting Settings](#php_ini_settings)
- [Turning Error Logging On](#turning_on)
- [Using int_set() to Display Errors](#using_int_set)
- [Maintain Your Log Files](#maintain)

**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](/support/edu/easyapache/how-to-check-the-version-of-easyapache-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_error*s 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*.

1. [Log into your cPanel](/support/edu/cpanel/how-to-log-into-cpanel/).
2. [Go to the *File Manager*](/support/edu/cpanel/using-file-manager-in-cpanel/). Select the home directory for your website (by default: *public_html*) and click **Go**.
3. 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 ; ![Report all PHP errors](https://www.inmotionhosting.com/support/wp-content/uploads/2013/01/website_website-troubleshooting_error_reporting_error-logging-2-report-all.gif)
4. [](/support/wp-content/uploads/2013/01/website_website-troubleshooting_error_reporting_error-logging-3-display.gif)[](/support/wp-content/uploads/2013/01/website_website-troubleshooting_error_reporting_error-logging-3-display.gif)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 ![Display PHP errors On](https://www.inmotionhosting.com/support/wp-content/uploads/2013/01/website_website-troubleshooting_error_reporting_error-logging-3-display.gif)

## php.ini Error Reporting Settings

![List of PHP Error reporting settings](https://www.inmotionhosting.com/support/wp-content/uploads/2013/01/website_website-troubleshooting_error_reporting_error-logging-1-list.gif)

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.ini | Description |
| --- | --- |
| 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_DEPRECATED | notices for the use of functions that will be retired in a future version |
| 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 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](/support/website/choosing-the-best-php-handler/).

1. [Log into your cPanel](/support/edu/cpanel/how-to-log-into-cpanel/).
2. [Go to the *File Manager*](/support/edu/cpanel/using-file-manager-in-cpanel/). Select the *public_html* directory and click **Go.**
3. You can set the following line of code to *On* to log errors or *Off* to turn error logging off. log_errors = On ![Log PHP errors On](https://www.inmotionhosting.com/support/wp-content/uploads/2013/01/website_website-troubleshooting_error_reporting_error-logging-4-log-errors.gif)
4.  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 ![Path to PHP Error log](https://www.inmotionhosting.com/support/wp-content/uploads/2013/01/website_website-troubleshooting_error_reporting_error-logging-5-path-to-log.gif)

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

1. [Log into your cPanel](/support/edu/cpanel/how-to-log-into-cpanel/).
2. [Go to the *File Manager*](/support/edu/cpanel/using-file-manager-in-cpanel/). Select the *public_html* directory and click **Go**.
3. Navigate to the PHP file you want to check errors for. Open the file in the code editor.
4. In the file, add the following at the top. ini_set('display_errors', '1'); 1 = On0 = Off
5. 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.
