A 504 Gateway Timeout error means a gateway – a CDN, a load balancer or the web server in front of your application – forwarded the request and gave up waiting for a reply. The backend is not necessarily down; it is too slow for that request. Fixing a 504 means finding what makes the request slow, or moving that work out of the web request.
Before you start
- Note which URLs return 504 – every page, or only heavy ones like imports, reports or checkout.
- Check whether a CDN such as Cloudflare is in front (its timeout shows as error 524 instead).
Common causes of a 504 error
- Slow PHP scripts – imports, exports, report generation, image processing.
- Slow database queries on large tables or locked tables.
- External API calls that hang without a timeout.
- Resource limits making every request crawl.
- Short proxy timeouts on a VPS (Nginx
proxy_read_timeoutorfastcgi_read_timeout).
How to fix it on cPanel hosting
- Identify the slow request in cPanel → Metrics → Raw Access and the error log.
- Check resource usage in Metrics → Resource Usage; frequent CPU or I/O limits slow everything. See I/O limits and slow websites.
- Move long tasks to cron or WP-CLI instead of running them from a browser.
- Optimise the site: enable LiteSpeed Cache, remove heavy plugins and clean the database. Our slow website guide lists the checks.
- Add timeouts to outgoing API calls in your code or plugin settings.
How to fix it on a VPS
- Check the backend is healthy: PHP-FPM status, free workers, CPU and memory.
- Find slow queries with the MySQL slow query log.
- Raise proxy timeouts only for specific long endpoints, not site-wide. See Nginx 504 Gateway Timeout.
Note: Increasing timeouts hides slowness. Visitors will not wait 5 minutes for a page; make the request faster or run it in the background.
FAQ
Is a 504 error a server outage?
Usually not. The server is up, but one request takes too long.
What is the difference between 504 and 524?
524 is Cloudflare's own timeout after 100 seconds; 504 comes from a gateway at your host or server.
Does the task continue after a 504?
Often yes. Check the result before rerunning it.
