Having a problem establishing a connection with the WordPress database? Perhaps you’re seeing the dreaded, “Internal Server Error 500” page when trying to access your site. Although WordPress hosting is generally a stable system, sometimes things can break it.
The important thing to remember is not to panic. When this problem happens, most of the time it’s a quick and easy fix. For example, something as small as a bad plugin might be causing the issue.
Today, I’m going to go over different methods that may fix the error establishing a database connection in WordPress. These are in addition to some of the most common WordPress errors and are easy to fix most of the time.
Which error are you getting?
Although some people group internal server errors and database connections in the same category, they are actually very different. Even though it’s easy to assume that server errors involve the database, this isn’t necessarily true. In fact, both of these issues have distinct methods of repair.
Error Establishing Database Connection
First, let’s address the database connection. Usually this will happen when credentials have been changed for the database. This results when:
- The website has been moved to a new web host.
- Access to the database has been reset by the host.
- The database has been corrupted by an external force, like a hack or a bad plugin.
To check the credentials of the website, I’m going to demonstrate FileZilla. If you don’t have this program yet, I’d suggest installing it. FileZilla is a very useful tool when it comes to troubleshooting your WordPress website.
Open the root directory of your WordPress host through FileZilla.
Scroll down to find wp-config.php.
Right-click the wp-config.php file and choose edit. Mac computer users will hold down the command key and click. This will open your text editing software. For Windows users, this will probably be Notepad unless you have something else installed.
Browse through the code until you find the credentials for the website. The database information is usually saved at the beginning of the wp-config.php file. The segment will look like:
Compare this information with that of your current database connection information. If you moved your database recently, the information may no longer be valid. At which point, you’ll need to set up the database again by inserting the current credentials. This often includes the HOST if the database is saved elsewhere.
If your settings are correct, simply close down the text editor and FileZilla. If you have to change them, remember to save the file to the root directory before closing FileZilla.
Allowing WordPress to Repair the Database
Another method that may be of use is by allowing WordPress to automatically repair the database. This is done by adding a snippet of code to the wp-config.php file I had you open in the previous steps.
Once you are in the text editor of the wp-config.php file, add the following code under the rest of the “define” segments:
Once it is placed and the file saved, you can access your website again and the WordPress repair screen will open. Simply click the “Repair Database” button and the system will go through its steps to repair what it can.
Internal Server Error 500
Fixing an internal server error is a bit more convoluted than the above example. This can be caused by a myriad of things and can be quite the pain to figure out. In reality, anything from bad .htaccess info to a bad theme can prevent WordPress from working.
So, let’s tackle some of the more common things that cause this error to show up.
Corrupt .htaccess File
A bad or corrupt .htaccess file can prevent the site from operating while throwing up the error 500 screen. Sometimes a plugin or other tool modifies the file incorrectly or if someone added improper code causes the problem. In either case, it’s relatively simple to fix.
Resetting the File From WordPress Admin
Go to Settings and click on the Permalinks function. Click the “Save Changes” button on the bottom and WordPress will recreate the .htaccess file. Even though you won’t make any changes to the settings, clicking the button will still force WordPress to make its adjustments.
If this doesn’t work, try removing the old .htaccess file and trying the above Save Changes again. This can be done by using FileZilla to log into the root access of the site and changing the name of the file to: .htaccess-old
You want to keep the file in case you need it for reference or if there is something within such as custom coding or settings. Plus, it’s always a good idea to have a backup of any file you plan to edit.
Deactivating All the Plugins
Plugins can cause all kinds of issues when they don’t play nice together. This is especially true when you try to use more than one that have the same purpose. For example, some SEO optimizing plugins don’t work well when put together and can cause a site to malfunction.
At any rate, disabling all of the plugins will give you a chance to see if this is the case.
Go to the plugins screen of WordPress and deactivate all of the plugins in the list. Don’t worry. They should all save any settings you are using.
Once the plugins are deactivated, open your website. If the internal server error is gone, this means one of your plugins is causing problems. Activate them one-by-one while checking the site after each by opening a new tab. As soon as the error 500 is displayed again, the last plugin you activated is causing the problem.
At which point, you might want to remove it and find an alternative for the service it provides.
A bad theme can also stop a site from loading correctly for visitors. This can be as simple as changing the theme to one that you absolutely know is working. You do this by going to Appearance in WordPress and activating the Twenty Sixteen theme. This theme was specifically designed and verified to work with WordPress. If your site loads just fine after activating it, then it means your other theme is corrupt.
Replacing the WordPress Core
If there is a problem within the WordPress core files themselves, you may need to upload a fresh copy. You do this by uploading the wp-admin and wp-includes folders from a new install. Essentially, these can be pulled out of the zip file you receive from the WordPress.org website. The can be uploaded using FileZilla. This will not remove any of your information, plugins or themes.
It Takes a Bit of Troubleshooting
Unfortunately, a lot of the problems you may come across require quite a bit of troubleshooting to find the root cause. Luckily, most problems in WordPress are relatively simple to repair. As long as you keep a cool head and don’t panic, you might find solutions to some of the most common problems in WordPress. When all else fails, it doesn’t hurt to seek professional assistance.
What kind of issues have you come across while using WordPress? How often do you use plugins or themes that are not featured through WordPress.org?
Author: Josh Dargie
My name is Josh Dargie and I’m the Operations Manager at GreenGeeks. I’ve been with the company since 2009. I have over 16 years of experience working with and for various web hosting providers specifically in development, day-to-day operations and customer service.