Oct 08, 2021
How to Enable WordPress Error Logging
When managing a WordPress website, you might come across some common WordPress errors. They can cause a range of issues and even lead to a fatal error if not fixed. One way to let you know exactly which errors have occurred is by turning on the WordPress error or debug log.
The process doesn’t require you to hire WordPress experts or be skilled in web development. As long as you’re tech-savvy, it can be done in just a few minutes. Keep reading as this article will further discuss why you need to enable WordPress error logs and how to do so.
Why Enable WordPress Error Logs?
The WordPress debug mode, or WordPress error log, tracks and documents glitches, saving them on the debug.log or error_log file. This will help you troubleshoot errors and come up with solutions to fix them.
By default, the WordPress error log function is disabled. Meaning, you won’t see any warnings and error messages, or find recordings of problems your WordPress website experienced.
Whether it’s your plugins or themes not working properly, an internal server error, or PHP errors, WordPress might only display the “The site is experiencing technical difficulties” message.
That message doesn’t explain what’s causing the trouble and it may take some time to fix it via trial and error. This can result in downtime and cause you to lose traffic and profit.
Hence, it’s important that you are informed about the errors your WordPress site is facing.
Before we proceed with the tutorial, make sure to backup your website. You will only be making minor changes to one of the core files of your WordPress site. However, if something happens and the website breaks, the backup files will make it easier and quicker to restore it.
Enabling WordPress Error Logs via the wp-config.php File
For this method, you will need to download and install an FTP client like FileZilla on your computer. It requires you to edit your wp-config.php file so make sure Filezilla is configured with the correct FTP credentials before continuing with the tutorial below:
- Open FileZilla and access the root directory or public_html folder of your WordPress site.
- Find the wp-config.php file, right-click and select View/Edit to open the text editor.
- Scroll down to the line:
/* That’s all, stop editing! Happy publishing. */
Above it, insert the following code:
define (‘WP_DEBUG’, true);
If the line of code is already in the wp-config.php file, simply change “false” to “true”.
- Then, add the line:
define (‘WP_DEBUG_LOG’, true);
- Open the File menu, and click Save.
- Select OK if FileZilla wants to overwrite the old version of the wp-config.php file with the new one.
Refresh the page once you’ve enabled the WordPress error logs. This is to trigger the error again so it’ll be recorded on the newly enabled debug log.
Do take note that the error message will not only be visible in the WordPress admin dashboard but also on your website’s homepage. Feel free to add the following line of code as well in the wp-config.php file:
define (‘WP_DEBUG_DISPLAY’, false);
The snippet tells WordPress to hide the messages so you can review the errors later.
Enabling WordPress Error Logs via hPanel
For Hostinger users, the easiest way to enable error logging is through the hPanel. There are two ways – through PHP configurations and by editing the .htaccess file. These methods are also implementable on other non-WordPress PHP-based websites.
Via PHP Configurations
- Access your hPanel, navigate to the Advanced section, and select PHP Configuration.
- Click on the PHP Options tab, then tick the log_errors box.
- Leave the display_errors box empty if you don’t want users to see error messages when they visit your site.
- Scroll down, and press Save.
Accessing the PHP error log to check the errors occurring on your website is now possible. Keep in mind that you’ll only see the errors that occurred after you enabled error logging. Previous errors will not be added to the log.
By Editing the .htaccess File
- From the hPanel dashboard, go to the Files section, then click on File Manager.
- Select the public_html folder, then click on the New File button located on the top-bar menu.
- Name the new file error_log.txt, then click Create.
- Right-click on the .htaccess file, and select Edit.
- Add the following code:
php_flag log_errors on
php_value error_reporting 32767
php_value error_log “error_log.txt”
- Select the SAVE & CLOSE button. That’s it – you’ve enabled WordPress error logs.
Where to Locate Your Error Log File?
After turning the debugging mode on, you may want to know where the log file is located. If you turned on WordPress debugging using an FTP client, follow the steps below:
- Open FileZilla and access your website’s public_html folder.
- Find and select the wp-content folder, then double click the debug.log file.
You’ll find a list of WordPress errors and issues that have been recorded since enabling the error logs, like so:
For those using hPanel, either through PHP configurations or the .htaccess file, you can find the WordPress error log in just a few clicks:
- Open your hPanel, navigate to Files, and select File Manager.
- Click on the public_html folder and you’ll find the error_log file.
- Double click to see the WordPress error logs.
If you enable debugging for a subdomain, keep in mind that the error log is in the subdirectory instead. For example, its path would be:
The WordPress error log, also known as the WordPress debug mode, is a great function for when your site is not working properly and you’re not sure why. It will help identify and record the source of the errors so you can fix them.
In this tutorial, you’ve learned how to turn on debug mode in a few different ways:
- FTP client/Filezilla – by editing the wp-config.php file.
- hPanel – through PHP configurations or editing the .htaccess file.
Once you have the debug mode on, the debug.log or error_log file can be found in your WordPress directory or public_html folder. However, keep in mind that the WordPress error logs will not show past problems the site faced.
Though it’s a simple process, remember to make a backup of your WordPress website files before you decide to enable error logs on the site.
If you still have questions about this topic, feel free to leave them in the comment section below.