WordPress Error Logs

How to Create and Access Error Logs for WordPress

When things go wrong on your WordPress website, error logs are your best friend. These files tell you what is causing the error, which makes it much easier to troubleshoot. However, sometimes they are not on by default.

Thus, many beginners may not even be aware that error logs exist in WordPress. The good news is that they’re easy to enable and view, and most importantly, they make troubleshooting common WordPress errors a cinch.

Just relying on the initial error message can be extremely confusing because a variety of things can cause the same problem. The error log provides a far more detailed view of what is going wrong, although it can sometimes be difficult for a beginner to read the logs.

Today, I will demonstrate how to enable debug mode to create an error log and where you can view it.

Why Use an Error Log in WordPress?

Errors can and will occur at any point while running a WordPress website. Using an error log has a lot of benefits. The error log will show you exactly what scripts are causing the error messages.

This will let you know if it is a plugin or theme and which specific install is causing the issue. This is also a great way to know if it is an error on your end or on your web host’s end.

If you do not see a script causing the problem, there is a number of things that can go wrong on your web hosts’ server.

Cyber attacks are very popular in today’s world, and new security measures are created to improve website security every day as we have recently done at GreenGeeks by introducing WordPress Protect.

Among the many types of cyber attacks, DDOS attacks are the most popular. These can overload any server and cripple your website. In this situation, there is not much either you or the web host can do until it is done.

It is also not uncommon for servers to stop working or have a momentary glitch. This could be because your web host is using outdated or old equipment. If this is the case, you may consider switching your web host.

How to Create WordPress Error Logs in WP-Config

Step 1: Locate the WP-Config.php File

No additional plugins are required to accomplish this task. You will need access to your website’s cPanel, which is provided by your web host when you create an account.

You should make a backup of your website before attempting this. This will ensure that if a mistake is made, you will be able to revert to the previous version of your website. That said, it’s pretty easy, so don’t worry too much.

Let’s start by logging into the cPanel and clicking on the File Manager option. The File Manager will allow you to access all of the files related to your website.

Click on the File Manager option.

You need to locate your theme’s wp-config.php file. Click on the public_html directory. Right-click on the wp-config.php file and select the Edit option.

select the Edit option.

A pop-up window will show up. This box will warn you to create a backup of your files before editing anything. This will ensure that you can revert your website back to when it was working if something goes wrong.

Click on the “Edit” button. A new tab will open containing all of the code from the file.

Click on the "Edit" button.

Step 2: Enable Debug Mode

Scroll down to the bottom of the code. Look for the comment line that says “That’s all, stop editing! Happy blogging” and paste the following code above it:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );

The first line may already appear in your code, but instead of the “true” value, it will have the “false” value. You must delete it before pasting this code in. This line will turn the WordPress debug mode on, while the second will create an actual log of the errors you encounter.

On top of being able to view all of the errors in your error log, you will also be able to see them as notifications in the admin area. Once you have inserted the code into the wp-config.php file, click on the “Save Changes” button to finish.

Click on the "Save Changes" button.

So, now you actually need to view the error logs you just enabled.

Where are the Error Logs Located in WordPress?

The logs are located in the wp-content folder. Inside this folder, look for the debug.log file. This contains the full error log of all of the pages you have encountered an error on while in debug mode.

You will not see this file if you have not encountered any errors. It only appears when something is written inside of it.

If you wish to disable debug mode at any time, edit the wp-config file and change the debug mode value from “true” to “false” and you will be back to normal.

Congratulations, you have successfully enabled debug mode and created an error log for your WordPress website.

How to View Your WordPress Error Logs in cPanel

WordPress error logs are very useful, but there is actually a second set of error logs that you can view directly in the cPanel. This set of error logs will focus more on your hosting environment and help troubleshoot a different set of problems.

Unlike the previous section, they are already enabled by default. Let’s get started by logging into the cPanel.

In the “Metrics” section, click the “Errors” link or icon.

viewing website error logs in cPanel

The “Errors” page will display the last 300 entries, or 2MB, of the server error logs.

the cPanel error log

The first part of each log entry is the date and time of the error. Following that are module and process ID information as well as the visitor’s IP address. But what you will typically be looking for is the error message itself.

In the example above, most errors are “File not found.” After the error message is the path to the missing file.

Once you know the cause of the error, you can check your site and fix it. Often the errors are caused by links to files that have moved or been deleted. These are usually easy fixes by changing or removing the links.

You may also see [NOTICE] errors such as, “bot detected for vhost.” The notice errors typically indicate that the connection to the site was closed by the server.

The reason for that varies from server to server, but the error log should indicate why the connection was closed. In this case, the server detected a bot that it considered potentially harmful, so the connection was terminated.

Here’s a link to Apache’s error logs page if you want to take a deep dive into server errors.

Know Exactly What is Causing the Errors in WordPress

You will encounter plenty of common WordPress errors that can cause you frustration and downtime for your website. An error log will tell you exactly what script from what plugin, theme, or other file is causing the error.

This will greatly speed up your website’s recovery time. Having a backup in place will ensure you can roll back if the error is causing significant downtime.

Not only will the log uncover what errors are your fault, but you will also be able to determine if some errors are your web host’s fault. If you are noticing regular downtime because of your web host, then it is time to switch.

Where are the errors coming from on your website? Do you like using the debug mode to uncover where the error is occurring?

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.