WebHostingPeople Blog

  • Domains
    • Shared Hosting

  • Cloud VPS
  • Servers
    • Client Area Login

How Can We Help?

How to Enable PHP Error Log for WordPress Sites

You are here:

This tutorial will teach you how to enable PHP error log for WordPress sites.

WordPress is the preferred free and open-source content management system which relies on PHP and MySQL. WordPress is used by more than 25% of the 10 million websites. A system administrator will eventually have to work with a WordPress site. For an administrator, error logs are clues that can be retrieved from apache log. However, WordPress comes with a special debug system designed to simplify the process as well as standardize code within the core, plugins, and themes. This guide will show you how to enable the debug option for a WordPress site and various configurations.

Improving the configuration file for Debugging

The primary configuration file of WordPress is the wp-config.php file. We have to make some configuration modifications to enable debugging in this file. The WP_DEBUG is the variable used for enabling debugging. It’s a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. It’s assumed to be false by default and is usually set to true in the wp-config.php file on development copies of WordPress

define( ‘WP_DEBUG’, true );

define( ‘WP_DEBUG’, false );

Enabling it will cause all PHP errors, notices, and warnings to be displayed on the website. To save the errors to a location WP_DEBUG_LOG is used. By configuring this option, we can save the error to a debug.log file in the wp-content directory in the Webroot.

define( ‘WP_DEBUG_LOG’, true );

To limit the errors that appear on the website, we have a WP_DEBG_DISPLAY option. Making this option false will allow you to hide the messages. The default is ‘true’ which shows errors and warnings as they are generated. Setting this to false will hide all errors. This should be used in conjunction with WP_DEBUG_LOG, so that errors can be reviewed later.

define( ‘WP_DEBUG_DISPLAY’, false );

An example configuration of error log on a WordPress site:

/**

* This will log all errors notices and warnings to a file called debug.log in

* wp-content (If Apache doesn’t have write permission, you may have to create

* the file first and set the appropriate permissions (i.e. use 660) )

*/

define( ‘WP_DEBUG’, true );

define( ‘WP_DEBUG_LOG’, true );

define( ‘WP_DEBUG_DISPLAY’, false );

The default debug log file is /wp-content/debug.log. Placing error logs in publicly accessible locations is a security risk. Ideally, your log files should be placed above your site’s public root directory. If you can’t do this, at the very least, set the log file permissions to 600 and add this entry to the .htaccess file in the root directory of your WordPress installation.

Order allow,deny

Deny from all

This prevents anyone from accessing the file via HTTP. You can always view the log file by retrieving it from your server via FTP.

There are other debugging plugins available which will provide more information about the internals. Query Monitor, Debug Bar, Log Deprecated Notices are just a few examples. Enabling these plugins can simplify debugging.

If you need any further assistance, please contact our support department.

Post Your Comment