WP_DEBUG option controls the reporting of some errors and warnings and enables use of the WP_DEBUG_DISPLAY and WP_DEBUG_LOG settings.
In this quick tutorial I will show you how to enable the WP_DEBUG feature and output the results to a log file.
Enable WP_DEBUG in wp-config.php
Edit the wp-config.php file, find this line and change the value from false to true:
define( 'WP_DEBUG', true );
TIP: You can also enable WP_DEBUG only for your IP and reduce harmful displays on a production site with the command (change 12.34.56.78 with your IP):
if ("12.34.56.78" === $_SERVER["REMOTE_ADDR"]) {
define( 'WP_DEBUG', true );
} else {
define( 'WP_DEBUG', false );
}
Enable WP_DEBUG from WP-CLI
If you have WPCLI installed run the following to enable debug mode:
wp config set WP_DEBUG true
Log WordPress errors to a file using the WP_DEBUG_LOG option
Another handy option is the WP_DEBUG_LOG, which in combination to the WP_DEBUG option will save all error messages into a debug.log file located inside the /wp-content/ directory.
To enable debug.log file, add the following code to the wp-config.php file:
define('WP_DEBUG_LOG', true);
Afterwards open the /wp-content/debug.log file and view the errors.
NOTE: Database errors are printed only if WP_DEBUG is set to true. Database errors are handled by the wpdb class and are not affected by PHP’s error settings.