How to enable debug in WordPress

  1. Home
  2. /
  3. WordPress How To Guides
  4. /
  5. How to enable debug in WordPress

In this lesson, we’ll show you how to enable debug in WordPress to help solve a white screen of death or internal server error message.

In our last lesson, we showed you how to solve the exhausted memory error. If you fail to get an email notifying you that this is the problem, you will need to follow this guide.

There may be certain times that you will need to enable debug mode to find the cause of faults and errors on your website. While WordPress now has inbuilt mechanisms to notify the website administrator of an error and the cause, there may be cases where you will be required to activate debug mode for WordPress. Such cases may be a critical error on the website but no email was received or when looking for a problem within a plugin that only happens sometimes. Another classic example is the dreaded white screen of death or internal server error. The good news is this is an easy task and we’ll show you how to enable debug mode in WordPress.

What is an internal server error and what causes it?

To new users who are using WordPress, this can be a deceiving warning message. When you first see this error you’ll at first assume that there is a problem with the hosting server. The reality is there is a problem with the website.

The internal server error is always caused by an error in the website PHP code, either from a theme, plugin or custom code. Essentially, what the server is saying is, it doesn’t know how to interpret the code because it hasn’t been correctly formatted. This coding error can result in a white screen of death, a message saying internal server error, or more recently a notice saying there has been a critical error on this website.

Why you might want to enable debug in WordPress

In some circumstances, you may not receive an email informing you of the problem, or the site will simply display a white screen. When this happens you have no way of determining the problem. I’ve also seen on some WooCommerce websites a conflict between plugins on the checkout page that is only triggered when the pay now button is clicked. Due to the way the checkout page uses Ajax the site has no way of displaying the critical error message, and it often simply displays a generic WooCommerce warning and scrolls to the top of the page. By learning how to enable debug in WordPress

How to enable debug in WordPress

1. Access the root install of your WordPress website through FTP, such as Filezilla, of through your hosting provider’s control panel file manager. The WordPress installation directory is normally found in the public_html folder. You will know that you are in the correct location when you see the folders wp-admin, wp-content and wp-includes as well as the wp-config file. This is the file we will need to access. It should look similar to below. Open the wp-config file to edit it

How to enable debug in WordPress

2. Now that wp-config is open and you can edit it, you will need to add a few lines to the file. This may seem intimidating, but it is safe. If you are concerned about making changes and breaking something, make a full copy of the contents. Simply download the wp-config file or copy the contents and paste it to a text editor.

3. Look for the following line

/* That's all, stop editing! Happy publishing. */

4. Just above that line enter the following line of code. This will enable debug in WordPress.

define('WP_DEBUG', true);

If the line currently exists but says false instead of true simply change the false to true

5. Click save. WordPress will now be in debug mode, but it will display all errors to frontend users. This isn’t ideal and you will undoubtedly want to avoid this.

6. Just below the last line you added add the following. This will stop the errors from displaying on the frontend

define('WP_DEBUG_DISPLAY', false);

Click save. Now, as you can see, the errors have stopped displaying, but you no longer get to see what’s causing the problems. We need to enable logging of the errors.

7. Just below the last line add the following It will store the errors in a text file that you can access.

define('WP_DEBUG_LOG', true);

Click save.

Right now your website will still be generating fatal errors and internal server error notices, but it will also be logging the faults and causes of them in a new log file. This log file can be found in the wp-content folder in a new file called debug.log

8. You can also degug other scripts aside from PHP. While errors in the other scripts won’t cause a white screen of death, a critical error message or an internal server error, they can cause display problems if it’s a CSS error or a functionality problem is it’s a Javascript error.

By default the script logging is disabled, but you can enable it with one more line of code. When it’s enabled the script debug logging will uncompress the WordPress JS and CSS files. Simply add the following line under the other lines of code and save the changes.

define('SCRIPT_DEBUG', true);

You can also enable database debugging. If you are experiencing problems with the database or database queries enabling database logging in WordPress can assist you in troubleshooting the problems

9. To enable database logging in WordPress simply add the following line below the others and click save.

define('SAVEQUERIES', true);

Ensure you use this code sparingly and don’t leave it enabled for extended periods of time. Enabling this will impact your website performance, so only use it when you need to.

You can use the following example of code to output the error log to a page.

    global $wpdb;
    print_r( $wpdb->queries );

Once you have finished debugging it is highly recommended to set all values to false and delete the debug file. Leaving debug active can cause problems with storage resources and be a security issue.

You can find out more from the WordPress debugging page found here

We hope you found our guide on how to enable debug in WordPress useful. If you have any questions at all please leave a comment below

0 0 votes
Article Rating
Spread the love
Written by: John Cook

Written by: John Cook


About: I'm John Cook. I'm a qualified web developer and data scientist, currently undertaking a Masters of data science at UNSW and a Masters of information technology with a specialisation in cybersecurity at CSU in Australia, a blogger, developer and WooCommerce fanboy. As the founder of Swift Designs, WC Success Academy, Wiz Plugins, Commerce Mania and Learn WP by Swift Designs, my goal is to empower website owners around the world to take full control of their WordPress powered websites. I've been developing websites for close to 10 years and have a deep understanding of WordPress and how it works. As an active plugin developer with several plugins in the WordPress plugin repository, this gives me a unique understanding of the inner workings of WordPress. My goal with Learn WP is to allow WordPress website owners the ability to discover the true potential WordPress has to offer in an uncomplicated and easy to understand way
Notify of
Inline Feedbacks
View all comments