Enable WordPress Debug Log (WordPress Debug Mode)

This article explains how to activate the WordPress debug mode and generate the debug.log file. You’ve likely found this article because you are experiencing a fatal error or a blank white page on your WordPress site. You can use WP STAGING to prevent such fatal errors on your production site!

You may get an error 500 or a blank page when you open your WordPress website. To determine what plugin or code is causing that error, you can tell WordPress to write all errors into a log file named debug.log or display them on the screen instead of showing just the white blank page.

How to activate WordPress Debug Mode

You can enable the WordPress “debug mode” by editing a few lines in the wp-config.php file of your WordPress installation:

  1. Login to cPanel or log in to your site via FTP
  2. Use the cPanel File Manager or your FTP client and edit the file wp-config.php
  3. Copy the lines below to the file wp-config.php or if they already exist, change their values to true:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Attention: Make sure that you copy the lines exactly as shown, don’t forget any semicolons or other characters!

    1. Paste the copied lines directly above the line that says
      /* That's all, stop editing! Happy publishing. */
This picture shows where to paste the copied lines based on the screenshot.
Please paste the copied lines, as shown in the screenshot.

After reloading the website, WordPress writes all PHP errors into the file debug.log.
WordPress saves that file into the folder: wp-content/debug.log

Display Errors in the WordPress Frontend

Take care when using this option: You and your visitors can see the front-end PHP error messages. For security reasons, disable the WP_DEBUG_DISPLAY constant after fixing your site errors.

If you want to see the debug log errors directly on the screen instead of activating the debug.log file, change the line that says

define( 'WP_DEBUG_DISPLAY', false ); to
define( 'WP_DEBUG_DISPLAY', true );.

Please send us the debug.log file when we ask you to do so.
This file allows us to resolve any technical issue you have.

WordPress Does not Create the debug.log Log File.

Some hosting providers[1] do not create the WordPress debug.log. They catch all errors and warnings made by WordPress and write them into a separate log file.

If WordPress can not create the debug.log, check if you see another file in the root directory, such as error_log or a folder/logs or similar.

If you do not see any error logs, please ask your hosting provider where they store the log files.

Please note when using the step below: You can see the PHP error messages in the front end and your visitors. If you no longer need the displayed errors for security reasons, make sure that you set the value back to “false.”

Alternatively, you can use the method mentioned above and change
define( 'WP_DEBUG_DISPLAY', false ); to
define( 'WP_DEBUG_DISPLAY', true );

If this works, you will see the relevant errors on the front end. That will help you to resolve the fatal error.

You can find more detailed instructions about enabling the WordPress “debug” mode at https://wordpress.org/support/article/debugging-in-wordpress/.

At the time of writing this article: [1] HostGator

Change the Location of the debug.log

You can change the position of written errors by changing the value of the constant WP_DEBUG_LOG:

define( 'WP_DEBUG_LOG', true ); to
define( 'WP_DEBUG_LOG','/logs/errors.log' );

That allows you to write the error messages into another file located elsewhere.

As a destination path, you can also write dev/stderr or /dev/stdout. That can help if you use Docker or another development environment and have all your logs in a shared location.

Disable Debug Mode in WordPress After Troubleshooting

We already mentioned this before, but If you are investigating WordPress website issues with the debugging mode, don’t leave it activated all the time. After using the debug.log, delete the file, and disable further error logging by changing the following lines from define( 'WP_DEBUG', true ); to define( 'WP_DEBUG', false );.

Otherwise, unauthorized persons could access that file and would be able to get sensitive information from your server.

Do not forget to disable the WordPress debug mode when you’ve finished investigating and troubleshooting your website issues!

Updated on April 13, 2022