Categories: TutorialsUbuntu

How to Enable WordPress Debug for Error Troubleshooting

Once you start with the websites, you might encounter different types of issues in the near time. Developing troubleshooting skills comes in handy to resolve such issues for a healthy website. Similarly, getting issues on WordPress sites is not a surprise. While browsing WordPress sites, there might be showing errors like “Error establishing a database connection”. It is difficult for a programmer, developer, or regular user to know the exact issue with these details.

To resolve such issues, getting the details on the issue comes in handy. For that, there are debugging methods for WordPress sites. It results in the details of the issue with the related logs which helps to resolve it quickly. Using a plugin is also a way to resolve the issues.

Sponsored

In this tutorial, we are going to discuss the WordPress debug mode and enable it on WordPress to get details of errors, which further helps to resolve the issue.

WordPress Debug Mode

In WordPress, you might like a new theme and install it that might not be compatible and conflict with other tools. Other cases such as changing database user, user password, database name might be wrong on the configuration file “wp-config.php”. So there might be any error that causes the error on the core PHP of the WordPress site.

Let’s take an example for our test site that shows the error as “Error establishing a database connection”.

Here, there might be any error which needs to be found to resolve the issue. Here comes the debug Mode, that helps to find the error logs to resolve the issue at the earliest for a healthy site.

Enabling the WordPress Debug Mode

Here, we are going to discuss the two methods to enable the WordPress debug mode which will display the error logs to resolve the issue. One of the methods is to change the configuration manually or you can use a plugin which will automatically add the code on the configuration file.

Installation of plugin

To enable the debug automatically, you can install the plugin by searching “WP Debugging” on the plugin section of the WordPress admin dashboard as shown in the screenshot below.

Install and activate the plugin. Then go to the tools section, you can find WP Debugging there. Tick “Set WP_DEBUG to true” to enable the debugging as shown on the screenshot below. It will display the errors on the site. As it might confuse the other users, you want to hide the errors on the site by ticking “Set WP_DEBUG_DISPLAY to false, default is true” as shown on the screenshot below. It will create a file “debug.log” where you can check the errors.

After resolving the issue, deactivate the plugin so the website can run smoothly with the provided contents.

Manually enabling the Debugging Mode

Most programmers or developers like to manually enable the debug mode by editing the configuration file “wp-config.php”. It is located in a public folder where all the site contents are available such as /var/www/html/test.com. Now open the configuration file “wp-config.php” where you can add the line of code for the debugging. Be default, you can find the code line just above the line “/* That’s all, stop editing! Happy publishing. */ .

You can edit the file by adding the code line “define( ‘WP_DEBUG’, true );”” to enable the debugging as shown on the screenshot below.

Sponsored

As soon as you add that line, all the PHP errors and vulnerabilities will be displayed on the website. Go through the screenshot below for one of the error cases.

While browsing the website, it might confuse the other users. So you want to hide the errors on the site by adding the other two lines of code. One of which will create a file containing the errors details on the wp-content directory and other code will stop displaying the errors on the site. Such line of codes are :

To create a file containing the errors details on the wp-content directory

define( 'WP_DEBUG_LOG', true );

To stop displaying the errors on the site

define( 'WP_DEBUG_DISPLAY', false );

You can see the screenshot below for the further details regarding the line of codes.

Go to the wp-content directory, and run the cat command to display the errors on the debug.log file as shown on screenshot below.

With the above details on the errors, resolving the issues will be easy. After the issue gets resolved, set “ ‘WP_DEBUG’, false” or remove those lines of code added for the debugging purpose.

Conclusion

With this knowledge of enabling the debugging for the WordPress site, you can easily detect the errors and resolve the issue as soon as possible. For the easy purpose, you can just install the plugin and enable the debug mode or manually edit the file and add the lines of code to enable debugging. Have a great time debugging!

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Ubuntu Server Admin

Recent Posts

Canonical announces 12 year Kubernetes LTS

Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…

17 hours ago

Ubuntu Weekly Newsletter Issue 878

Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…

1 day ago

How your feedback shapes the way we support open source software

At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…

2 days ago

How To Install osTicket v1.14 On Ubuntu 20.04

I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…

3 days ago

How To Install WordPress On Ubuntu 20.04

Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…

3 days ago

How To Install DNS Server (Bind9) On Ubuntu 20.04

Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…

3 days ago