7 Ways to Fix a 502 Bad Gateway Error in WordPress

That gut-drop moment when you try to load your WordPress site and see nothing but a blank page with the words "502 Bad Gateway" – your revenue is frozen, your leads can't reach you, and every minute of downtime chips away at your SEO rankings and trust. The most common cause is a failed FastCGI or PHP process on your server, and the quickest fix is often a simple restart of your PHP service or a browser cache flush. Before you dive into any troubleshooting, back up your site and database and create a full file-level backup of your publichtml directory.

Common causes of a 502 Bad Gateway error in WordPress

A 502 error means your server (the gateway) received an invalid response from another server upstream. Here are the primary culprits:

1. Refresh your browser and clear server cache

Sometimes the error is a one-time hiccup. Press Ctrl + F5 (Windows) or Cmd + Shift + R (Mac) to force a hard reload that bypasses your local cache. While you are at it, clear any server-side cache your hosting panel or caching plugin (like WP Rocket or W3 Total Cache) uses. Log into your hosting control panel (cPanel, Plesk, or your host's custom dashboard) and find the "Clear Cache" option. Restart the web server (Apache or Nginx) if that option is available – a simple restart resolves many transient 502 errors.

2. Disable all plugins and switch to a default theme

If refreshing doesn't work, the next most common trigger is a faulty plugin or theme. Access your site via FTP (or your host's file manager) and navigate to /wp-content/plugins/. Rename the entire plugins folder to pluginsold. This deactivates every plugin at once. If your site comes back, rename the folder back to plugins, then reactivate plugins one by one until you find the offender. Follow the same process for themes: navigate to /wp-content/themes/, rename your active theme folder (e.g., twentytwentyfour) to twentytwentyfourold. WordPress will automatically fall back to a default theme like Twenty Twenty-Four.

3. Increase the PHP memory limit

When a WordPress site runs out of PHP memory, the process crashes and triggers a 502. Edit the wp-config.php file in your site's root directory. Add this line just before the / That's all, stop editing! / comment:

define('WPMEMORYLIMIT', '256M');

If your hosting provider allows it, you can also increase the limit via the php.ini file:

memorylimit = 256M

For sites on shared hosting, you may need to add this to your .htaccess file instead:

phpvalue memorylimit 256M

After making the change, restart PHP or your web server and check if the error resolves.

4. Check and repair your .htaccess file

A corrupted .htaccess file can force Apache into a rewrite loop, returning a 502. Connect via FTP and locate .htaccess in your WordPress root directory. Download a copy as a backup, then delete .htaccess from the server. Visit your WordPress admin login page (/wp-admin/). If the page loads, go to Settings → Permalinks and click Save Changes. This regenerates a fresh .htaccess file with the correct rewrite rules. If you had custom redirect rules, add them back one at a time and test.

5. Restart PHP-FPM and web server services

If you have root-level access (VPS or dedicated server), the fastest fix is restarting the services directly. For Nginx with PHP-FPM, run these commands via SSH:

sudo systemctl restart php8.1-fpm
sudo systemctl restart nginx

For Apache:

sudo systemctl restart httpd
sudo systemctl restart php8.1-fpm

On cPanel servers, you can restart services through the WHM → Restart Services interface. Most managed WordPress hosts also provide a one-click service restart in their dashboard.

6. Disable your CDN temporarily

If you use Cloudflare, StackPath, or another CDN, the reverse proxy may be communicating poorly with your origin server. Log into your CDN dashboard and pause the service or set it to Development Mode. In Cloudflare, toggle Development Mode on from the Speed tab – this bypasses the cache for three hours. Test your site without the CDN. If the 502 disappears, flush your CDN cache, check for misconfigured page rules or SSL/TLS settings, and then re-enable the service. The most common misconfiguration is setting the SSL/TLS encryption mode to Flexible instead of Full (Strict) – this breaks the handshake and produces a 502.

7. Monitor server resource usage and upgrade your plan

Persistent 502 errors often signal resource caps. Log into your hosting control panel and look for resource usage graphs (CPU, memory, I/O, entry processes). If you consistently hit 100% of any metric during traffic spikes, your current plan cannot handle your load. Compare a few hosting tiers to see what you need:

Hosting PlanPHP WorkersMemory LimitMonthly Visitors (approximate)Price Range
Shared entry5–10128 MB1,000 – 5,000$3 – $10
Shared high-end15–25256 MB10,000 – 25,000$15 – $30
VPS entry30–50512 MB50,000 – 100,000$20 – $50
Managed WordPress50+512 MB – 1 GB100,000+$30 – $100+

If you are on a budget shared host, consider upgrading to a managed WordPress host that scales PHP workers automatically.

8. Examine PHP error logs for the real root cause

The error message 502 tells you that something crashed, but not what. The actual details live in your PHP error logs. Access logs via your hosting panel → Error Log, or connect via SSH and tail the log file:

tail -100 /var/log/phperrors.log

Look for entries stamped at the same time the 502 appeared. Common clues include:

Search the specific error message online – it often points directly to a plugin or theme function.

9. Reset or flush DNS cache

If you recently changed nameservers or moved your site to a new host, your local DNS cache may still point to the old server, which returns a 502. Clear your local DNS cache:

Also check that your domain's A record resolves to the correct IP using an online DNS checker. Propagation can take up to 48 hours, so if you are mid-migration, set up a temporary URL to work on the new server while DNS propagates.

10. Disable or reconfigure your firewall (server-level)

A server firewall (like CSF or ModSecurity) can block legitimate PHP requests and cause a 502. Access your server via SSH or WHM and temporarily disable the firewall to test. If the 502 resolves, identify the specific rule. For CSF, check /etc/csf/csf.deny for blocked IPs or enable CSF Test Mode. For ModSecurity, add your IP to an allowlist temporarily. Never leave the firewall disabled – customise the rules instead.

11. Re-upload core WordPress files

Core WordPress files can corrupt over time, especially after failed updates. Download a fresh copy of WordPress from wordpress.org. Extract the zip file locally, then upload the wp-admin and wp-includes folders to your server via FTP, overwriting the existing ones. Do not overwrite wp-content or wp-config.php. After uploading, visit /wp-admin/ and click the prompt to update the database if one appears.

12. Check for a reverse proxy or load balancer misconfiguration

If you use Nginx as a reverse proxy in front of Apache, or a load balancer with multiple backends, one backend may fail silently while others keep running. Check the upstream configuration in your Nginx config file (usually /etc/nginx/sites-available/your-site). Look for the upstream block and verify each backend server is reachable:

upstream backend {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}

Test each backend IP directly with curl. If one returns a timeout, restart that service or remove it from the pool until it is fixed.

How to prevent a 502 Bad Gateway error from recurring

Proactive monitoring and maintenance reduce future downtime. Set up a free uptime monitor (like UptimeRobot or Better Stack) that alerts you the moment your site goes down. Schedule weekly checks for PHP memory usage and MySQL connections. Keep your WordPress core, themes, and plugins updated – outdated plugins are the number one cause of process crashes. If your site runs on shared hosting, set a calendar reminder every three months to review your resource usage and upgrade before you hit a limit.

For site owners who manage multiple WordPress installations, a tool like nativeWP can streamline your content workflow after you fix the backend – it automates bulk SEO article creation and publishing directly to WordPress, so you can focus on growing traffic instead of wrestling with server configs. Check out nativeWP for a smarter way to manage content across your sites.

Frequently asked questions

What is the difference between a 502 Bad Gateway and a 503 Service Unavailable error?

A 502 Bad Gateway means one server (the gateway) received an invalid response from another server upstream – usually a PHP process crash. A 503 Service Unavailable means the server is temporarily overloaded or down for maintenance. The fix for a 502 focuses on upstream services like PHP-FPM, while a 503 often requires adding server resources or reducing traffic.

Will clearing my browser cache fix a 502 error permanently?

No – clearing your browser cache is only a diagnostic step to rule out a cached version of the error page. If the 502 is caused by a server-side issue (crash, memory limit, plugin conflict), it will return on the next page load. Use the browser refresh to test, but always investigate the root cause on the server.

Can a 502 error be caused by a DDoS attack on my WordPress site?

Yes, a DDoS attack can flood your server with requests, exhausting PHP workers and triggering a 502. Check your server's network traffic logs for abnormal spikes. If you suspect an attack, enable your hosting provider's DDoS protection, use Cloudflare's Under Attack Mode, and block suspicious IPs via your firewall.

Should I contact my hosting provider first when I see a 502 error?

If you are on a managed WordPress hosting plan, contact support first – they have direct access to restart services and check server logs. For unmanaged VPS or dedicated servers, try the steps in this guide first (especially restarting PHP-FPM and checking error logs), then open a support ticket if the issue persists.

How do I know if the error is on WordPress side or the server side?

Check your server's error log for PHP fatal errors (server-side) or HTTP requests that never reach WordPress. You can also create a simple static HTML file (like test.html with the text "Hello Server") and place it in your root directory. If the static file loads fine but WordPress pages give a 502, the issue is with PHP or your WordPress configuration – not the server itself.

Key takeaways