WordPress 504 Gateway Timeout: The 7 Real Fixes (2026)
Disclosure: some links on this page are affiliate links. We may earn a commission at no extra cost to you. How we test and rate hosts.
A 504 is a waiting problem. The gateway knocked, PHP never answered within the timeout - usually ~30-120 seconds. Either something is genuinely too slow (a query, an import), or PHP can't answer at all (workers saturated, server overloaded). Here's how to tell which, then fix it.
1. Refresh, Then Check Scope
One reload can clear a transient spike. Then scope it: whole site timing out = server/PHP layer problem. One page or one operation (import, export, report) = that operation is too heavy - skip to fix 4. Only via Cloudflare = fix 2.
2. Rule Out the CDN
Cloudflare has a ~100-second hard timeout to the origin - if your server takes longer, Cloudflare returns its own branded 504 even when the server eventually finishes. Enable Development Mode or pause Cloudflare to test the origin directly. If direct works, either speed up the operation or move it off the web request entirely (WP-CLI, cron).
3. Deactivate Plugins
A hanging plugin holds a PHP worker until the gateway gives up. FTP: rename wp-content/plugins to plugins_off, reload. Site responds? Reactivate one at a time. Classic offenders: anything doing external API calls per pageview, backup/migration plugins mid-job, and security scanners running deep scans.
4. Find the Slow Query
Page-specific 504? Install Query Monitor on a staging copy (or briefly on production) - it lists every database query with timing. You'll usually find one query eating seconds: an unindexed meta query, a WooCommerce report over 50k orders, a "related posts" query scanning wp_posts unindexed. Fix the query, add an index, or cache the result - don't raise timeouts to accommodate it.
5. Split Heavy Operations
Imports, exports, and bulk edits that 504 aren't fixable by waiting longer - the gateway timeout is a wall. Split them: import 500 rows at a time instead of 50,000, use WP-CLI (wp import runs without HTTP timeout), or run heavy jobs as real cron tasks. This is why managed hosts offer WP-CLI - command-line PHP doesn't have a gateway waiting on it.
6. Timeouts: The Last Lever, Not the First
If the operation is legitimately long and can't be split, raise the ceilings - all of them, or the lowest still wins:
- -PHP:
max_execution_time = 300in php.ini (details in our execution time fix) - -Nginx:
proxy_read_timeout 300;(VPS only) - -Apache:
Timeout 300in server config
On shared hosting you control none of these - which is the point: if your workload needs 5-minute web requests, it's outgrown shared hosting.
7. Server Overload and DNS
Check cPanel > Resource Usage for CPU/IOPS faults at the 504 timestamps - saturated resources timeout exactly like this. Recent DNS change? Requests may hit the old server where PHP is dead. And if clean diagnostics still show timeouts under modest traffic, that's the hosting telling you it's undersized.
Timeouts Under Load = Wrong Plan
Bluehost measured 241ms average TTFB in our 90-day test - requests that answer in a quarter second don't hit 100-second gateway walls. From $3.99/mo.
Get Reliable HostingRelated: 502 bad gateway fix - 503 service unavailable - max execution time fix - database optimization.
What are you building?
Tell us about your project so we can match the perfect hosting plan.
Hosting Cost Calculator
See exactly how much you'll spend on hosting over time. Compare Bluehost vs popular alternatives and discover your potential savings.
Used to calculate transaction fees (Shopify charges 2% on sales)
Frequently Asked Questions
What causes a 504 Gateway Timeout in WordPress?
The gateway (nginx/Apache/CDN) asked PHP for the page and timed out waiting. Causes: a slow database query or heavy operation, PHP workers saturated by traffic, a plugin hanging, server overload, or the CDN unable to reach the origin in time.
What's the difference between 502 and 504?
502 = PHP sent back a bad or empty response. 504 = PHP never responded before the gateway's patience ran out. In practice 504 points to slowness (queries, imports, overload) while 502 points to crashes. The diagnostic order overlaps heavily.
What's the fastest fix for 504?
Refresh once - brief spikes self-resolve. If it's one slow page or operation (import, report, big update), that operation is too heavy: split it into chunks. For site-wide 504s, deactivate plugins via FTP and check the CDN (Cloudflare Development Mode).
Why does 504 only happen on certain pages?
Page-specific 504s mean that page's code is too slow - usually an unindexed database query, a looped API call, or a page builder rendering thousands of elements. Use Query Monitor on a staging copy to find the exact slow query.
Can raising max_execution_time fix a 504?
Only partially. PHP's limit can be raised, but the gateway's timeout (nginx proxy_read_timeout, Cloudflare's ~100s hard limit) kills the request first if it's lower. The real fix is making the operation faster, not making everyone wait longer.
Is 504 a hosting problem?
Frequently - timeouts under normal traffic mean insufficient CPU/PHP workers. But a single plugin running a 5-minute query will 504 on any host. Diagnose the operation first; blame the plan only when the site is clean and still timing out.
Ready to launch?
Get Bluehost from $3.99/month with a free domain, free SSL, and 30-day money-back guarantee.
Related Articles
Bluehost vs Competitors: The Technical Deep Dive
We ran 47 benchmarks over 90 days. Here's the raw data on why Bluehost dominates.
Fix ERR_TOO_MANY_REDIRECTS in WordPress (2026): The 6 Real Causes
ERR_TOO_MANY_REDIRECTS means an infinite redirect loop. Match your Site URLs, fix Cloudflare SSL mode, reset .htaccess, kill plugin conflicts - step-by-step with code.
WordPress 403 Forbidden Error: 7 Fixes That Actually Work (2026)
403 means the server understood you but refuses to serve the page. Fix file permissions (755/644), regenerate .htaccess, kill security plugin blocks - in the right order.
Fix 502 Bad Gateway in WordPress (2026): Diagnose First, Then Fix
502 means the gateway got a bad response from your server - usually PHP timeouts, CDN issues, or overload. A 9-step diagnostic workflow from browser checks to server logs.
Fatal Error: Maximum Execution Time Exceeded - 6 Fixes (2026)
max_execution_time kills slow updates at 30-60s. Fix the culprit plugin/theme first, then raise the limit via wp-config, .htaccess or php.ini - with exact code.
HTTP Error Uploading Images in WordPress: 9 Fixes Ranked (2026)
The vague 'HTTP error' on image upload usually means memory limits or Imagick. Fix order: rename the file, bump memory, force GD library, check permissions - with code.