Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Fix 500 and 502 Errors in WordPress

DZone's Guide to

How to Fix 500 and 502 Errors in WordPress

500 and 502 errors can occur on WordPress, and can also be hard to fix as the errors provide very few pieces of information about what's going on.

· Web Dev Zone ·
Free Resource

Bugsnag monitors application stability, so you can make data-driven decisions on whether you should be building new features, or fixing bugs. Learn more.

500 and 502 errors can occur on your WordPress site, and can also be hard to fix since the errors themselves are providing few pieces of information about what's going on. In order to help you fix those errors, here's a simple and handy guide.

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 an FTP to access your web server and navigate to your website's root directory. Rename the .htaccess file into, for example .htaccess.old.

Once this is 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 an 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 web server) into something like plugins.deactivated.

Re-Uploading 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 Temporarily

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 such as white screen, 400 or 403. Recently, I came across a very good guide by 000webhost.

000webhost.com 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.

Monitor application stability with Bugsnag to decide if your engineering team should be building new features on your roadmap or fixing bugs to stabilize your application.Try it free.

Topics:
wordpress ,errors ,web dev ,web performance

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}