How to fix 500 and 502 errors in WordPress

How to fix 500 and 502 errors in WordPress

Caution: always backup your site before proceeding!

What are the causes of these errors?

It’s important to note that WordPress itself isn’t at fault: 500 errors can occur on every website, and for a wide variety of reasons. Those errors are typically frustrating and demand a lot of troubleshooting since the error itself doesn’t provide any pointer about what can be wrong.

In WordPress, the cause of those errors mostly occurs in the root directory, or because of a host problem.

Fixing 500 errors

Fixing the .htaccess file

.htaccess is a configuration file for use on web servers running the Apache Web Server software. It contains various rules regarding your website configuration, such as the structure of your permalinks.

Since a corrupt .htaccess file is responsible for most 500 errors, you should always start there if such an error is occurring on your site.

The first thing to do is to rename your current .htaccess file. Use a FTP to access your web server and navigate to your website’s root directory. Rename the .htaccess file into, for example .htaccess.old.

Once done, simply log into your WordPress dashboard, navigate over Settings, and select Permalinks. Scroll down to the bottom of the page, and click Save Changes. This will regenerate a fresh .htaccess file, and your site will be accessible from now on if the cause of the error was a corrupted .htaccess file.

Increasing memory limit

Another common cause of 500 errors is when a script is requesting more memory than the server is allocating. It can occur when using a poorly coded plugin or theme.

A quick fix to the problem is to try to increase the memory limit. To do so, use a FTP to access your web server and navigate to your website’s root directory. Open the wp-config.php file and add the following:

define('WP_MEMORY_LIMIT', '128M');

Depending on the limit set on your server by your host, it could fix the problem. But keep in mind that memory problems happen because of a badly written plugin or theme, so the long-term solution is to find the faulty piece and remove it from your site.

Deactivating plugins

If the solutions above haven’t worked, deactivating plugins could be a way to identify where the problem comes from. If you recently installed a plugin, then this plugin should be deactivated since it’s most likely the cause of the error.

If you haven’t installed any new plugins, it’s still worth a try to deactivate all your plugins. To do so, you can simply rename the plugins directory (under wp-content on your webserver) into something like plugins.deactivated.

Reuploading WordPress core files

If everything else has failed and the 500 error is still occurring, then you might need to re-upload WordPress core files. What you need to do is to download a fresh copy of WordPress, and then upload the wp-admin and wp-includes directories on your site root.

Be careful not to upload the wp-content directory, as this would erase all your themes and plugins.

Fixing 502 errors

The 502 Bad Gateway error is an HTTP status code that means that one server on the internet has received an invalid response from another server. Those errors are often caused by issues between online servers that you have no control over. However, it can also happen that there’s no real issue but your browser thinks there is one.

Check if the site is globally down

Since your browser can be at fault in the event of a 502 error, the first thing to do is to check whether the issue is global, or if you’re the only one to see it.

Down For Everyone Or Just Me is a very handy tool that will let you know instantly if your website can still be accessed by others.

Clearing cache

If it looks like your site can be accessed by others but not you, simply refer to your browser documentation on how to clear your cache.

Quick tip: pressing the Ctrl and F5 keys simultaneously forces a cache refresh of the page.

Disable your CDN temporary

There is a possibility that a 502 error occurs because of an issue with your Content Delivery Network. In that case, you can choose to temporarily disable your CDN. The same goes for WP Rocket or any other plugin that you might have hooked up to a CDN.

DNS issues?

DNS issues, such as the domain name not resolving to the correct IP, can also result in 502 errors. If you just migrated your WordPress site to a new host, it can take up to 24 hours for the DNS to propagate. Get in touch with your host and/or domain name technical support for assistance.

Other errors

Unfortunately, it can happen at times that WordPress site owners might run into other errors as such as white screen, 400 or 403. Recently, I came across a very good guide by 000webhost. has prepared a detailed and user-friendly guide on how to fix error 403 on WordPress. You can check it by visiting the site yourself and exploring a few more tutorials.

Original post: How to fix 500 and 502 errors in WordPress

This article was first published at
Go to original post source
Email, print or share this page: