How to

504 Gateway Timeout Error in WordPress: 5 Simple Fixes

You click a link on your website, the browser tab spins continuously for thirty seconds, and then the page finally collapses into an error screen:

504 Gateway Timeout

A 504 Gateway Timeout error means that one server acting as a gateway or proxy did not receive a timely response from an upstream backend server while trying to load the webpage.

In simple terms: your website tried to complete an operation, but the backend took too long to finish, and the server gave up waiting.

In this troubleshooting guide, we will cover the common causes behind the 504 gateway timeout error in WordPress and provide five actionable fixes to get your site running fast again.


What Causes a 504 Gateway Timeout in WordPress?

A 504 error is strictly a timeout failure. In WordPress environments, it usually stems from:

  • Heavy Database Queries: Massive database requests (like ecommerce reports or imports) running longer than the maximum execution threshold.
  • Slow External API Calls: A plugin making third-party API calls (to payment processors, analytics, or licensing servers) that hang indefinitely.
  • Underpowered Web Hosting: A spike in traffic maxing out CPU and RAM resources on shared hosting.
  • Proxy and Firewall Timeouts: Cloudflare or another CDN timing out after waiting more than 100 seconds for an origin response.

Fix 1: Reload and Check for Server Traffic Spikes

Occasionally, a sudden influx of visitors or automated spam bots can temporarily saturate your web server’s processing queue.

Wait sixty seconds and hit Ctrl + F5 (or Cmd + Shift + R) to perform a hard refresh.

Log in to your hosting cPanel and check the CPU and Memory Usage monitor. If resource usage was at 100% during the crash, your site was simply temporarily overwhelmed.


Fix 2: Turn Off Your VPN or Proxy Server

If you are browsing with a VPN or proxy enabled, routing hangups between your VPN tunnel and your web host can falsely generate a 504 error.

Disable your VPN software and test loading the site using your standard mobile data connection. If the website loads cleanly on mobile, the issue was with your local network connection or VPN server.


Fix 3: Disable Cloudflare or CDN Proxy Temporarily

If your website sits behind Cloudflare, you will often see a branded Cloudflare error page with Error 504: Gateway Timeout.

To determine if Cloudflare is the bottleneck or your origin server:

  1. Log in to your Cloudflare dashboard.
  2. Select your domain and go to the Overview tab.
  3. Scroll down to the bottom right and click Pause Cloudflare on Site.
  4. Wait five minutes for DNS to propagate, then reload your site.

If the site loads without Cloudflare, your origin host is taking too long to return data to Cloudflare edge nodes, usually due to low execution limits.


Fix 4: Increase PHP Execution Time Limits

By default, most web hosting servers set PHP maximum execution time to 30 seconds. If a plugin takes 31 seconds to compile, the server cuts the connection with a 504 error.

You can increase your execution window to 300 seconds via your .htaccess file:

  1. In cPanel File Manager, open public_html/.htaccess.
  2. Add this line at the bottom:
php_value max_execution_time 300

Alternatively, if you use a php.ini file, add:

max_execution_time = 300

Save changes and test the page that was timing out.


Fix 5: Repair and Optimize Your WordPress Database

A cluttered database filled with millions of expired transient options, spam revisions, and fragmented tables will cause database queries to stall, triggering 504 timeouts.

  1. Log in to cPanel and open phpMyAdmin.
  2. Select your WordPress database from the left sidebar.
  3. Check all tables, scroll to the bottom dropdown, and choose Optimize table.
  4. You can also click Check table to ensure no tables are corrupted.

For additional server optimization tips, review our tutorials on fixing the failed to write file to disk error and resolving 413 request entity too large issues.


Wrapping Up

Resolving a 504 Gateway Timeout error comes down to increasing execution time allowances and making sure your backend database has the resources required to finish its tasks.

Did increasing your execution time clear up your 504 error? Leave a comment below with your setup details!

Leave a Reply