Need help? Chat now!

Hostwinds Tutorials

Search results for:


Table of Contents


Editing Your .htaccess
Test Your Error Log
View your error files

How to create a PHP Error log in cPanel

Tags cPanel 

Editing Your .htaccess
Test Your Error Log
View your error files

This guide will explain how to create a PHP error log file in cPanel for your primary domain name. This will require you to add and edit files in the file manager, including the .htaccess to follow along in this guide. If you have trouble diagnosing errors on your site, this guide can help provide some more information by enabling error logs.

Editing Your .htaccess

Step One: Navigate to the File Manager in your cPanel

Step Two: Select the public_html folder and the folder for your domain.

Step Three: By default, the .htaccess file is hidden. Click on Settings on the upper right side of the page to view the settings.

Step four: Click on the Save button.

Step Five: Back in your file manager, right-click your .htaccess file, and select edit.

Step Six: Copy and paste the following code in your .htaccess file and click on Save Changes:

php_flag display_errors off
php_flag log_errors On
php_value error_log /home/Username/public_html/phperror.log

You will need to change the Username  above to your cPanel username

This will put the error log in the file named phperror.log in your public_html folder or create this if the file does not exist. You can customize the location of the file or the file name by editing the file path.

Step 6b: Locate your cPanel/FTP username in your cPanel homepage in the upper right corner of your cPanel homepage

You can add an error log for each domain by creating a separate .htaccess file in the domain's document root. You can combine these by keeping the file path as shown above for the phperror.log file the same.

Test Your Error Log

Step One: Create a new PHP file named errortest.php in your public_html folder and add this code to produce an error:

\<!?PHP
function fun1()
{
ech "SHOW ME THE ERROR";
}
fun2();
echo "Fatal Error !!";
?>

This will produce an error due to the incorrect spelling of echo and using it instead.

Step Two: Access the file using your favorite browser. For example, go to the file from your domain, ex.  domain.com/errortest.php

This will cause an error to be logged in your ~/public_html/errortest.php file, and nothing will show up on this page.

View your error files

Option One: Right-click the phperror.log and select view

Your phperror.log should look like this when it has been created.

Option Two: You can also view the phperror.log file by going to 'domain.com/phperror.log' (replace 'domain.com' with your actual domain)

Written by Hostwinds Team  /  September 20, 2018