2 Ways to Get WordPress Error Logs

by

When it comes to troubleshooting issues on your WordPress site, WordPress error logs are a godsend. Logs are snapshots about issues on your site, showing verbose error messages so you can resolve them easily.

WordPress sites are not set up to log error information by default. However, certain web hosts do enable logging on their dashboards. Hence, in this article, we show you how you can check if your web host does provide error logs, and how to enable logging on your WordPress site if it doesn’t.

TL;DR: If your web host does not provide WordPress error logs, enable them by using either a plugin or by editing the wp-config.php system file.

Check if your web host provides WordPress error logs

Most web hosting services recognize the importance of logs in troubleshooting and provide logging capabilities by default.

For instance, if your web host uses cPanel for website administration (eg. GoDaddy, Hostgator, WPEngine, etc.), you can find your logs in the Errors tab of the Metrics section.

cPanel -> Metrics -> Errors

Similarly, if you are a Cloudways user, you can easily find Access and Error Logs by navigating to the Application Management tab and selecting Monitoring.

Cloudways Access and Error Logs

However, some web hosts take a manual approach. For example, Kinsta allows you to enable debugging logs from the dashboard with just one click, but you can access them only through FTP or SSH. In contrast, DreamHost does not have any explicit settings to enable debugging; instead, it requires you to edit the wp-config.php file, a step that we will be discussing later. If you use any other web host, check their documentation for further information.

In case your web host does not provide the feature to create error logs, you can set them up manually.

How to create WordPress error logs

WordPress error logs can be created either by using a plugin or by manually editing the wp-config.php file to enable debugging logs on your site.

Create WordPress error logs using a plugin

Several plugins are available on the WordPress plugin store that can help create logs. However, we prefer using WP Debugging by Andy Fragen. It is a simple plugin that provides several features right off the bat. Here are the steps to use it:

  1. Install and activate WP Debugging: From the Plugins option of your WordPress dashboard, click on Add New Plugin. Search for WP Debugging, click on Install, and then on Activate to enable logs on your WordPress site.
WP Debugging
  1. Install and activate the companion plugins: This is an optional step, however, we recommend it due to the sheer number of additional features provided. From the Tools menu, click on WP Debugging to access its dashboard. You will see notifications to add the Query Monitor and Debug Bar plugins. Install and activate them to avail database logs, dashboard control bar, etc.
  1. Select options from the WP Debugging dashboard: On the dashboard, Set WP_DEBUG to true is selected by default. Leave it as it is. There are two other options that can be left unchecked as they are
WP Debugging Dashboard
  1. Start logging: Click on Save Changes and you are ready to go.

Create WordPress error logs by editing the wp-config.php file

The plugin method suffices for most users as it is easy and creates the error logs in the default location of the logs folder in the root directory. However, if you are a power user who wants to create the error logs in a separate directory/file, the plugin does NOT offer you the option to do so. In that case, you may want to use this manual method of creating WordPress error logs.

WordPress has a debug constant used to create a log of all errors experienced on the site. This constant is not enabled by default, so you would need to make some edits to a core file.  

It requires you to edit the wp-config.php system file using either File Transfer Protocol (FTP) or Secure Shell (SSH). Hence, we recommend that you back up your site using a WordPress backup plugin like BlogVault before you start editing a critical system file. This will help you recover your site in case of any errors or mistakes.

Now that you have created a backup of your site, let’s see how you can edit the wp-config.php file and enable error logs on your WordPress site.

Editing the wp-config.php file using FTP

This is the simpler method to edit the wp-config.php file among the two. Here are the steps to do so:

  1. Connect to your WordPress site using an FTP client: For this method, you will need to use an FTP client like Filezilla. Upon downloading and installing the app, open it and enter the credentials like host IP address, username, password, and port number (if any). All these details can be obtained from your web host. Finally, click on Quickconnect.
  2. Locate and open the wp-config.php file: After connecting to your site, find the wp-config.php file in the root folder. This folder may also be called the public_html folder and can be found in the right-side panel of your Filezilla window. Right-click on it and click on View/Edit. This downloads a temporary version of the wp-config.php file using your default text editor.
  3. Edit wp-config.php to enable debugging: In the wp-config.php file, find the following line of code and replace the false value with true.
define( ‘WP_DEBUG’, false );

Hint: Use Ctrl+F on PCs or Command+F on Macs to find the code faster.

  1. Add additional code to wp-config.php: Add the following lines of code right after the line from step 3:
if ( WP_DEBUG ) {
@error_reporting( E_ALL );
@ini_set( ‘log_errors’, true );
@ini_set( ‘log_errors_max_len’, ‘0’ );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
define( ‘CONCATENATE_SCRIPTS’, false );
define( ‘SAVEQUERIES’, true );
}

These lines of code control various parameters for the log files. The statements beginning with @ are to control how PHP errors are logged. The define statements control whether debug logs are saved in a debug.log file, whether error messages appear on the webpage itself, how scripts are loaded on the site, etc.

  1. Upload wp-config.php back to your site: Save the file by entering Windows + S on PCs and Command + S on Macs. Upon closing the editor, you will see a dialog box pop up that asks if you want to upload the file to your site and replace the existing one. Click on Yes and you are done.

Note: If you are comfortable with using cPanel, you can use its File Manager to edit the wp-config.php file. Simply locate your file, right-click on it, and select Edit. A dialog box will show up warning you to create a backup of the file, and you can click on Edit again. After that, follow steps 3 and 4 to make the changes.

Editing the wp-config.php file using SSH

This method is more technical than the FTP one and requires you to use Command Prompt on PCs or Terminal on Macs. Here are the steps to do it:

  1. Connect to your site using SSH: Start by obtaining your SSH credentials from your web host. Next, enter the following command on Command Prompt or Terminal to connect to your WordPress site:
ssh username@ipaddress

This will prompt you to enter your password to connect to your site.

  1. Locate the wp-config.php file: Once you are in, move to the folder where your wp-config.php file is located. Usually, it is the root folder, typically named public_html or www. To do that, enter the following command:
cd public_html
ssh cd public_html

Next, locate the wp-config.php file by entering the following command:

ls -a

This brings up the list of files in the folder.

ssh ls -a public_html
  1. Edit wp-config.php: Enter the following command to open the wp-config.php file in the Vmacs editor:
vi wp-config.php
vi wp-config.php

Hit i to enter edit mode and locate the following line of code:

define( ‘WP_DEBUG’, false );

Replace the false value with true. Directly below this line of code, add the following lines as well:

if ( WP_DEBUG ) {
@error_reporting( E_ALL );
@ini_set( ‘log_errors’, true );
@ini_set( ‘log_errors_max_len’, ‘0’ );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
define( ‘CONCATENATE_SCRIPTS’, false );
define( ‘SAVEQUERIES’, true );
}
  1. Save the edits to wp-config.php: Hit Esc to exit edit mode and type the command :wq to save the wp-config.php file and exit the Vmacs editor.

To save the debug logs in a particular file or directory

If you wish to log the error data to a different directory/file, edit the WP_DEBUG_LOG statement from the above lines of code to replace the ‘true’ value with the path to your desired directory/file, as shown below:

define(‘WP_DEBUG_LOG’, ‘your_directory_path/error_file.log’ );

Remember, error logs can leave your site vulnerable to hacking attempts as they contain sensitive information like usernames, full paths to directories on your sites, etc. So use error logging only for debugging purposes. Once done, deactivate the plugin (if you are using the plugin method) or delete the lines of code added to the wp-config.php file and set the WP_DEBUG value to false (if you are using the manual method). After that, delete your debugging logs as well.

How to find and check your WordPress error logs

If your web host provides an error logging feature, you can simply access it from your web host’s dashboard.

In case you set up logging for your WordPress site, you can find and check your logs by using FTP or SSH.

Checking WordPress error logs using FTP

  1. Connect to your site using FTP: Use the steps mentioned earlier to connect to your site using an FTP client like Filezilla.
  2. Locate error logs: If you have manually set up debugging on your WordPress site, the error logs will be located in the wp-content folder as debug.log or in your specified directory. If you have used a plugin like WP Debugging, these logs will be present in the root directory in a folder called logs. Sort them according to a decreasing order of creation dates to find the latest ones.
  3. Download your error log file: Once you have located your error log files, download them by right-clicking on them and selecting Download. This will download the file to the location selected on the left pane of your Filezilla window. If you wish to download the file to any other location, navigate to that location using the left pane.
  4. Open your error log file using a text editor: Now that you have downloaded the error log, open it using Notepad or any other text editor you prefer. You can scroll through the data and identify the exact message informing you of the error/issues.

Checking WordPress error logs using SSH

  1. Connect to your site using SSH: Use the steps mentioned earlier to connect to your site using Command Prompt for PCs or Terminal for Macs.
  2. Locate error logs: As mentioned in the steps to check error logs using FTP, the files will be located in the wp-content folder, logs folder, or the folder of your choice. Navigate to the required folder by entering the following command:
cd your_folder/logs_folder

where your_folder/logs_folder can be replaced by the correct location.

Next, enter the following command to list all the files in that folder:

ls -a
  1. View your error logs: To view your error logs, simply open your required file in the Vmacs editor by entering the following command:
vi file_name

where file_name can be replaced by the error log name.

You can scroll through the logs using the arrow keys. Enter :q to quit the editor.

If you are looking for a particular message or timeframe, you can use the grep command instead of opening the file in an editor. Type the following to find the particular text you are searching for in the error log file:

grep text file_name

where text is what you are searching for and file_name is where you are searching for it.

How to fix issues discovered in WordPress logs

The debug.log file provides valuable information about errors and warnings on your WordPress website. However, they can appear technical to most users, which is why understanding these messages is critical to resolving any issues.

Each entry in the debug.log file typically includes the date, time, module, process ID, visitor’s IP address, and finally the error message. This error message is often enough to understand the problem. However, to fix the problem, you will have to go through guides and how-tos on it.

debug.log

To simplify the process of understanding the contents of the debug.log file, here are the steps:

  • Identify the error or warning in the debug.log file.
  • Look up the meaning of the error code to understand the specific issue.
  • Refer to guides or resources to find solutions for fixing that particular error.

When should you obtain WordPress logs

WordPress logs can help you identify sources of errors and also prevent them in the future. They also give you a look into how your site functions whenever an action is taken on it. 

However, you do not need these logs at all times. As we have mentioned earlier, debugging logs could potentially help hackers due to the treasure trove of information they contain. So it is important to know when you should obtain WordPress logs.

Here are a few scenarios when WordPress logs can be helpful for you:

  • If your WordPress site has crashed, is unresponsive, or not loading
  • If you get HTTP warnings like 401, 404, 504, etc. when loading your website or any specific pages on it
  • If you see any of your themes or plugins not working properly
  • If you want to see which of your themes or plugins are causing problems
  • If you want to see why your website is slowing down
  • If you suspect malicious actors on your site and want to check your site activity

Troubleshooting

If you are unable to obtain logs even after following the steps mentioned above, you can try the following steps:

  • Check whether the debugging plugin is compatible with your WordPress version, or if it has an update available. If it requires an update, update safely.
  • Check if the code you entered into wp-config.php is correct. A minor mistake could be enough to prevent your site from logging data.
  • Check if a plugin on your site is preventing the wp-config.php file from being edited. Usually, security plugins do this as a measure of protection against unwanted modifications to system files.

In the third case, you might need to disable the plugin during the debugging process. However, it is not advisable as disabling a security plugin could render your WordPress site vulnerable to threats. This is why we recommend using MalCare, a robust security plugin that not only protects your site but also has activity and firewall logging built in.

Final thoughts

In conclusion, obtaining WordPress error logs is the go-to process whenever you face any issues with your site. The insights gained from these logs can not only help you troubleshoot and resolve issues more efficiently but also provide a clearer understanding of what’s happening behind the scenes of your website. As a website owner/developer, the ability to track and interpret error logs is invaluable.

FAQs

How do I get WordPress to show errors?

You can get WordPress to show errors either by using a plugin like WP Debugging or by editing the wp-config.php file and setting the define( ‘WP_DEBUG’ ) statement to true. You can then also set the define( ‘WP_DEBUG_LOG’ ) statement to true as well so that all errors are logged in the debug.log file, stored in the wp-content folder.

Is there a WordPress error log?

WordPress does not log errors by default. However, some web hosts do provide access and error logs on their dashboards that you can easily obtain. In case your web host does not provide logs, you have to enable it by using a plugin like WP Debugging or by editing the wp-config.php file.

How do I find the debug log in WordPress?

You can find the debug log for your WordPress site in the wp-content folder. To do so, access your site through FTP using a client like Filezilla or Cyberduck and download the debug.log file to your system. You can then open it in any text editor and resolve issues, if any.

Where is the wp-config file?

The wp-config.php file is located in your WordPress site’s root directory. You can access your site using FTP and find this file alongside other critical folders like wp-admin, wp-content, etc. Remember, this is a file critical to your site’s health, so always back up your site before you make any modifications to it.

Category:

You may also like


Website logs
What are the Different Types of Website Logs?

Imagine driving a car without knowing your speed, engine temperature, or fuel levels. Sounds terrifying, right? Well, managing a website without understanding website logs is a bit like that. You…

cross-site-scripting-xss-attacks-what-how-prevent-them
What is Cross-Site Scripting (XSS) and How to Prevent It?

Websites can sometimes act strangely, showing unexpected pop-ups or exposing personal information. This isn’t just a glitch—it’s often due to a sneaky trick called Cross-Site Scripting (XSS). You might be…

How can we help you?

If you’re worried that your website has been hacked, MalCare can help you quickly fix the issue and secure your site to prevent future hacks.

My site is hacked – Help me clean it

Clean your site with MalCare’s AntiVirus solution within minutes. It will remove all malware from your complete site. Guaranteed.

Secure my WordPress Site from hackers

MalCare’s 7-Layer Security Offers Complete Protection for Your Website. 300,000+ Websites Trust MalCare for Total Defence from Attacks.