Nov 04, 2019
How to Check Your Website’s PHP Error Log
Many error messages don’t give much information about what you should do to resolve it. For that reason, it is recommended to use the PHP error log, a file responsible for recording site errors and telling which specific line code that needs fixing. Keep scrolling to find out how to enable this feature!
Enabling PHP Error Logging
Before tweaking some code and settings, make sure to check whether PHP error logging is enabled on your hosting account. Open your PHP information, press CTRL + F and search for log_errors value.
If the value is set to Off, there are a few ways to turn it on depending on your hosting platform.
This article will show you how to enable error logging by adjusting some settings in Hostinger’s control panel and editing the .htaccess file
Method 1: Using hPanel
The easiest way to activate the PHP error logging is through the Hostinger’s hPanel. Follow these simple steps:
- Login to the hPanel and find the PHP Configurations tool, located under the Advanced section.
- Switch to the PHP Options tab, and tick the log_errors box. Click Save.
An error log will be automatically generated in your public_html directory.
Method 2: Editing .htaccess File
If you don’t use Hostinger, PHP error logging can also be enabled by editing the .htaccess file. Read this tutorial to know how to locate the file, and then do the following steps:
- Create a file called error_log.txt in the public_html directory. All errors will be logged into this file.
- Open .htaccess and insert the following line:
php_flag log_errors on php_value error_reporting 32767 php_value error_log "error_log.txt"
- Click Save, and that’s it! You’ve successfully enabled PHP error logging.
When you re-check your PHP info, the Local Value should be on, while the Master Value is still off. However, pay no mind to the master value because it is overridden by the local value.
Opening the Error Log
Now that you’ve activated the PHP error logging, any PHP error that occurs on your website will be logged into the error log file.
To test if it works, add an extra symbol to your code and refresh the site. Afterward, use File Manager to open the error log file and check if there are any new entries:
Here are some examples of common errors that can help you analyze the log entries:
- PHP Parse error: syntax error, unexpected ‘2’ (T_LNUMBER), expecting ‘)’ in /home/u802426761/domains/username/public_html/wp-config.php on line 54 means that there is a syntax error in your code. To fix this issue, check the file and the line number mentioned in the message.
- PHP Fatal error: Call to undefined function get_header() in /var/www/username/public/blog/wp-content/themes/theme/index.php on line 1 warns that the index.php page is trying to call a function that does not exist. Check whether the function name is correct.
- Fatal error: Maximum execution time of 30 seconds exceeded in /home/username/domains/domain.com/public_html/wp-includes/class-phpmailer.php on line 737 could be resolved by modifying max_execution_time via PHP Configurations or .htaccess file. Check out our article to know how to do it.
In this quick tutorial, you’ve learned the two methods of enabling PHP error logging: tweaking the settings in hPanel and editing the .htaccess file. By using this feature, you’ll know what’s wrong with your site when it crashes unexpectedly. Pretty cool trick, right?
Leave a comment if you have any questions!