In this Blog we are going to learn how to setup Error logs for WordPress sites.
Today, WordPress has become the most popularly used free and open-source content management system and that is based on PHP and MySQL. WordPress powers more than 25% of all the websites that is running today. To handle a WordPress Site we need an expert that is generally a System Admin. These Error logs are treated as a clue by admin and are retrieved from Apache log. Although, WordPress provides a special system for debugging that is designed so it can simplify the whole debugging process. WordPress debugging system also normalize code beyond the core, plugins, and themes. This tutorial blog will teach you how to set up the debugging system in a WordPress site and enable its various configurations.
WordPress Error logs are generally set up in wp-config file. The whole controlling of your WordPress site settings is done by wp-config file, and it also helps in finding and fixing errors hence is a very useful debugging tool. This helps by identifying the plugins or scripts that are causing errors and hence you can check and remove them. Without its helps it would be quite tiring and time-taking process to find what is causing the error. So, now you know how important it is to set up the Error logs in WordPress.
Setting up WordPress Error Logs in WP-Config File
First thing you will need to do is connect to your website through FTP client or File Manager app in cPanel,so that you can access and edit your wp-config.php file.
In the root directory of your Website you will find your wp-config.php file. Open that file in any text editor that you prefer and start looking for the line written as ‘That’s all, stop editing! Happy blogging.’
Just before this line you need to add the following line of code:
, true );
define( 'WP_DEBUG', false );
WP_DEBUG is a PHP constant (a permanent global variable) that is used to start the “debug” mode throughout WordPress. It is supposed to be set at false by default and is usually set to true in the wp-config.php file on development copies of WordPress. So, in your file if it set as false then you need to change it to true.
By only doing this will start the WordPress debug mode. But there is a drawback of using this debugging alone that is your WordPress errors and warnings will be shown inside your admin area along with the front page of your website, which is not what you want.
To show the errors to admin location WP_DEBUG_LOG is used. By enabling this option, you can save the error to a debug.log file in the wp-content directory in the webroot.
For doing this, you will have to add the following code in your wp-config.php file just below the WP_DEBUG line.
, true );
To block the errors to be shown in the website’s front page. We have another option of using WP_DEBG_DISPLAY. By making this option false will hide the error messages on your website’s front page. By default it set to ‘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 );
Just save your changes and upload your wp-config.php file back to your website.
Reviewing Your WordPress Error Logs
For viewing your error logs first thing you need to do is visit your WordPress site and access those pages that were resulting in errors or warnings. After that, you will have to connect to your website through a FTP client or file manager app in your WordPress hosting cPanel.
Once you are connected, go to /wp-content/ folder .And, you will see a file called debug.log.
This file contains all the WordPress errors, warnings, and notices that were logged.You can download, view, or edit this file as per your need.
That all you have to do set up the Error logs in your WordPress website.There are also some debugging plugins available which will show more information about the internals. Query Monitor, Debug Bar, Log Deprecated Notices are just some examples. Enabling this plugin can make debugging straightforward.
Setting Up PHP Error Logs
For setting up error logs in PHP, you need to add few changes in two directives in the php.ini file:
First, with the help of a text editor set the log_errors directive as shown below:
log_errors = On In the next step, change the error_log directive to log PHP errors to a specific file. You will have to change path with the desired path to the log file, and filename with the desired log filename:
error_log = /path/filename
Save the php.ini file and don’t forget to upload it back to the server.