In this guide, we 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 are having 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 in 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 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:
ech "SHOW ME THE ERROR";
echo "Fatal Error !!";
This will product an error due to the incorrect spelling of echo and using ech instead
Step Two: Access the file using your favorite browser. 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 this 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)
By default, the permissions will be set so anyone can view the file. Learn How to Change the Permissions on a File