Technical

WordPress 504 Gateway Timeout: The 7 Real Fixes (2026)

By Daniel Reyes•October 8, 2026•3 min read

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.

Our top pick for most WordPress sites
Bluehost: free domain, free SSL, 24/7 support, 30-day money-back guarantee.
Check Bluehost Deal →

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 = 300 in php.ini (details in our execution time fix)
  • -Nginx: proxy_read_timeout 300; (VPS only)
  • -Apache: Timeout 300 in 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 Hosting

Related: 502 bad gateway fix - 503 service unavailable - max execution time fix - database optimization.

Find Your Perfect Hosting Plan

What are you building?

Tell us about your project so we can match the perfect hosting plan.

Question 1 of 425% complete
Interactive Tool

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)

Shopify Basic (3yr)
$1,044
Bluehost (3yr)
$444
You Save
$600
58% less than Shopify Basic

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.

Start for $3.99 →

Related Articles