November 4, 2019
November 4, 2019
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!
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
The easiest way to activate the PHP error logging is through the Hostinger’s hPanel. Follow these simple steps:
An error log will be automatically generated in your public_html directory.
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:
php_flag log_errors on php_value error_reporting 32767 php_value error_log "error_log.txt"
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.
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:
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!