Skip to content
Maintenance and security

500, 502 and 504 Errors: What They Mean and How to Fix Them

A 500 means your site's code failed, a 502 means a server got a bad answer from the one behind it, and a 504 means it waited too long. Causes, safe first steps and when to call for help.

Harsh PrajapatiFull stack developer
Published
Reading time
8 min

500, 502 and 504 Errors: What They Mean and How to Fix Them

A 500 error means your website's own code or server hit a problem it could not handle, such as a PHP fatal error or running out of memory. A 502 means a server in front of your site (a proxy, load balancer or Cloudflare) got an invalid response from the server behind it, and a 504 means it got no response in time. All three are server-side problems, so visitors cannot fix them; the fix is in your site's code, hosting or server settings.

This guide is for business owners and managers whose site is showing one of these errors, or showed one recently. It explains what each code means, the common causes on WordPress and on servers, what you can safely check yourself, and when to stop and get help.

#What each error means

The codes are defined in the HTTP standard (RFC 9110), and MDN summarises them in plain terms.

CodeNameWhat it meansWhere to look first
500Internal Server ErrorThe server hit an unexpected condition and could not complete the requestThe PHP or application error log
502Bad GatewayA gateway or proxy got an invalid response from the server behind itWhether PHP-FPM or the app process is running
503Service UnavailableThe server is temporarily unable to handle the request, often maintenance or overloadHost status, maintenance mode, resource limits
504Gateway TimeoutA gateway or proxy got no response in time from the server behind itSlow pages, long-running requests, timeouts

The useful difference: with a 502, the server behind the proxy answered but the answer was broken or the connection dropped. With a 504, it never answered within the time allowed. MDN also notes that a 504 can come from the visitor's own network (VPN, firewall, DNS), so if only one person sees it, check from another connection first.

#Common causes on WordPress

On WordPress sites, most 500 errors trace back to one recent change.

  • A PHP fatal error after an update. A plugin or theme update that does not work with your PHP version or another plugin. Since WordPress 5.2, this often shows as "There has been a critical error on this website" instead of a bare 500, and WordPress tries to email the site's admin address a recovery link. That email goes to the admin address stored in the database, which may be an old developer's.
  • Memory exhausted. WordPress tries to give PHP 40 MB by default on a single site (64 MB on multisite), and many hosts allow more. Heavy page builders, large imports or WooCommerce reports can exceed the limit. The log shows "Allowed memory size exhausted".
  • A broken .htaccess file on Apache servers, often after a security or cache plugin edited it.
  • A PHP version change by the host, where old code stops working on the new version.
  • Wrong file permissions after a migration or manual upload.

If the error appeared straight after updating something, our guide to what to do when a WordPress update breaks your site walks through the rollback.

#Common causes on servers: PHP-FPM, timeouts and upstreams

On a VPS or cloud server, the website usually runs as a chain: Nginx or Apache receives the request and hands PHP work to PHP-FPM, a pool of PHP worker processes. The front server is the "gateway" and PHP-FPM, Node.js or another app is the "upstream".

  1. Visitor
  2. Cloudflare (optional)
  3. Nginx or Apache
  4. PHP-FPM workers
  5. Database

Each link can fail in its own way:

SymptomLikely causeWhat a server admin checks
502 on every pagePHP-FPM or the app process is stopped or crashedService status, recent restarts, out-of-memory kills
502 or 504 only at busy timesAll PHP workers busy; pm.max_children sets the most requests PHP-FPM serves at oncePHP-FPM log for "max_children reached", memory per worker
504 on slow pages (reports, imports, exports)Request takes longer than a timeout. Nginx's fastcgi_read_timeout defaults to 60 seconds, PHP's max_execution_time to 30 secondsSlow queries, external API calls, raising the limit only for that page
500 with "memory exhausted"PHP memory limit too low, or a leak in one pluginPHP error log, the plugin involved
Errors after a server moveWrong socket path, PHP version or file ownershipNginx and PHP-FPM config, permissions
Random errors with a full diskDisk 100 percent full, so logs, sessions and the database cannot writeDisk usage, old backups and logs

Raising timeouts and memory limits treats the symptom. If a page needs more than a minute to load, the real fix is usually a slow database query, a slow external service or a job that should run in the background.

#Cloudflare's 52x errors

If your site uses Cloudflare, you may see Cloudflare's own error page with a 52x code. These mean Cloudflare is working, but the connection between Cloudflare and your server failed.

CodeMeaningCommon cause
520The server returned an unknown errorThe server sent an empty or invalid response, often a crash
521The web server is downWeb server stopped, or a firewall blocking Cloudflare's IP addresses
522Connection timed outFirewall or rate limiting blocking Cloudflare (the most common cause, per Cloudflare), an overloaded server, or an old server IP in Cloudflare DNS
523Origin cannot be reachedNetwork or DNS problem reaching the server
524A timeout occurredServer connected but took longer than 125 seconds to respond
525SSL handshake failedServer's SSL setup does not match what Cloudflare expects
526Invalid SSL certificateFull (strict) mode with an expired or wrong certificate on the server

For 524 errors on long tasks like large exports, Cloudflare suggests moving those requests to a subdomain that is not proxied, or reworking them to run in the background. Our guide to setting up Cloudflare for a business website covers SSL modes, which cause most 525 and 526 errors.

#Safe first steps for a site owner

These steps are safe for a non-developer and do not risk making things worse. Do them in order.

  1. Note the details. The exact error text, the time (with time zone), which pages show it and whether it happens for everyone. Cloudflare asks for the same details when you contact your host.
  2. Check if it is just you. Try a phone on mobile data. If it works there, the problem may be your network.
  3. Check your host's status page for an outage in your data centre.
  4. Undo the last change. If you updated a plugin, theme or PHP version just before, roll it back, or restore the backup taken before the change.
  5. Read the error log. Your host's control panel usually has an error log. The line at the time of the error usually names the file and plugin involved.
  6. Disable the plugin it names, or if you cannot log in, rename that plugin's folder in the file manager. Do not delete plugin files.
  7. Ask your host to check resource limits, PHP workers and server logs, giving them the details from step 1.

Do not turn on WordPress debug display on a live site; WordPress's own handbook advises against using debug tools on production. If you need the log, write errors to a file instead of showing them on the page.

#When to get help

Get help straight away when the error affects your checkout, payments or logins, when it keeps coming back at busy times, when the error log points to the server rather than a plugin, when you run your own VPS, or when the site may have been hacked (unknown files in the log, strange redirects). Every hour of a 500 on a store is lost orders.

Our emergency WordPress fixes service handles critical errors, white screens and broken updates, usually starting with the logs and a safe rollback. For 502 and 504 errors on your own server, VPS and cloud server management covers PHP-FPM, Nginx, resource limits and Cloudflare. To catch the next one early, see our guides to website monitoring tools and a backup and disaster recovery plan.

Frequently asked questions

What is the difference between a 502 and a 504 error?

A 502 means the server behind the proxy sent an invalid response or the connection failed, while a 504 means it sent no response within the time limit. Both come from a gateway such as Nginx, a load balancer or Cloudflare.

Can a plugin cause a 500 error in WordPress?

Yes, a plugin or theme is the most common cause of 500 errors on WordPress, usually after an update. The error log names the file involved, and renaming that plugin's folder deactivates it.

How do I fix a 504 Gateway Timeout?

Find which page or task is slow and fix the cause, such as a slow database query, an external API or a heavy report. Raising the timeout only helps for genuine long tasks, and only for that page.

Is a 500 error my host's fault?

Sometimes, but usually not. Most 500 errors come from the site's own code, plugins or settings. Host-side causes include outages, resource limits and PHP version changes, so check the host's status page and ask them for the server log.

What does Cloudflare error 522 mean?

It means Cloudflare could not connect to your server in time. Cloudflare says the most common cause is a firewall or rate limit on the server blocking Cloudflare's IP addresses, followed by an overloaded server or an outdated server IP in DNS.

Sources

The facts in this article were checked against these pages, last reviewed 12 November 2026.

  1. 500 Internal Server Error, MDN Web Docsdeveloper.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/500
  2. 502 Bad Gateway, MDN Web Docsdeveloper.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/502
  3. 504 Gateway Timeout, MDN Web Docsdeveloper.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/504
  4. RFC 9110: HTTP Semantics, IETFrfc-editor.org/rfc/rfc9110.html
  5. Cloudflare 5xx errors, Cloudflare docsdevelopers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/
  6. Error 522, Cloudflare docsdevelopers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-522/
  7. Error 524, Cloudflare docsdevelopers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-524/
  8. Debugging in WordPress, WordPress Advanced Administration Handbookdeveloper.wordpress.org/advanced-administration/debug/debug-wordpress/
  9. Editing wp-config.php, WordPress Advanced Administration Handbookdeveloper.wordpress.org/advanced-administration/wordpress/wp-config/
  10. Fatal error recovery mode in 5.2, Make WordPress Coremake.wordpress.org/core/2019/04/16/fatal-error-recovery-mode-in-5-2/
  11. FPM configuration, PHP manualphp.net/manual/en/install.fpm.configuration.php
  12. Runtime configuration, PHP manualphp.net/manual/en/info.configuration.php
  13. ngx_http_fastcgi_module, nginx documentationnginx.org/en/docs/http/ngx_http_fastcgi_module.html
Harsh Prajapati, the author

Written by

Harsh Prajapati

Freelance full stack developer, founder of Worklancio

Web developer since 2018, freelancing since 2022. Builds WordPress sites and plugins, web apps and CRMs from Ahmedabad.

You may also like