Help

How to fix the 504 Gateway Timeout error

“504 Gateway Timeout” means a server that passes requests on, such as a CDN or the web server in front of PHP, waited too long for the server behind it to answer. Visitors can wait a few minutes and reload. Site owners should find the slow script, query or cron job and make it faster, often with caching.

Updated · HostUpIndia team

What does 504 Gateway Timeout mean?

A 504 comes from a gateway or proxy, not from the server that builds the page. The CDN, load balancer or web server in front asked the server behind it for the page and gave up waiting. The server behind may still be working on the request.

The page can read “504 Gateway Timeout”, “504 Gateway Time-out”, or “Gateway time-out” with “Error code 504” on Cloudflare. If the server sends no page of its own, Chrome shows “This page isn’t working” and Edge “This page isn’t working right now”, both with “HTTP ERROR 504”. Firefox may show a blank page.

A 502 is a different error: the server behind sent a broken answer. See how to fix the 502 Bad Gateway error.

  • A slow PHP script or database query.
  • A heavy plugin or theme that does too much on every page load.
  • An import, export or backup that runs inside a page request.
  • Too many cron jobs, or WordPress scheduled tasks, running at once.
  • A call to another service, such as a payment or shipping API, that hangs.
  • A server that is overloaded or has reached its resource limits.
  • A CDN that cannot reach your server because of DNS or a firewall.

If you are visiting the site

A 504 is almost always on the website’s side. These checks rule out your own device and network.

  • Wait a few minutes, then reload the page once.
  • Open another website. If it loads, your connection works.
  • Open the page in a private window or another browser.
  • Turn off any VPN or proxy, then reload. A proxy at work or school can time out too.
  • Try another network, such as mobile data instead of Wi-Fi.
  • If the error came after you paid or sent a form, check your email or account before you try again. The order may have gone through.
  • If the 504 shows everywhere, the site’s server is at fault. Try again later or tell the site’s owner.

If it is your website: find the slow part

Narrow it down before you change anything. The logs are listed by time, so start with when it happened.

  • Note the time the 504 appeared and which pages show it.
  • Load an image or other static file on the site. If it loads fast but PHP pages time out, the cause is PHP, the database or the app.
  • If only one page fails, such as a search, report, import or checkout, the code behind that page is too slow.
  • Check your email and client area for a maintenance or outage notice from your host.
  • In cPanel, open Metrics › Errors and read the entries from the time of the 504.
  • In File Manager, open the error_log file in your site’s folder, usually public_html, if there is one.
  • If your cPanel lists Resource Usage under Metrics, check whether the site reached its CPU or process limits at that time. See how to fix “508 Resource Limit Is Reached”.
  • If the 504 shows on every page, even a static one, open a support ticket. Give the time of the error, the page and what you have tried.

Fix a 504 from slow pages, plugins or cron jobs

Most 504s on shared hosting come from a page that does too much work while the visitor waits. Make that work faster, cache it, or move it out of the page load.

  • Before you change files or plugins, open cPanel › Backup and download a home directory backup and a database backup.
  • On WordPress, rename the folder of the plugin you added or updated last in wp-content/plugins, for example plugin-name to plugin-name-off.
  • Load the slow page. If it loads in time, update or replace that plugin before you turn it on again.
  • If it still times out, rename the folder back and try the next most recent change.
  • On WordPress, add a page cache. If your host runs LiteSpeed, install and activate the LiteSpeed Cache plugin. Cached pages load without running PHP or the database.
  • Run large imports, exports and backup plugins as cron jobs or in smaller batches, not in a page load.
  • Open cPanel › Cron Jobs and space out jobs that run every minute or at the same time.
  • On a busy WordPress site, add a cron job in cPanel › Cron Jobs that runs every 15 minutes, with the command wget -q -O - https://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1, using your own domain. See how to set up a cron job in cPanel.
  • Then add define( 'DISABLE_WP_CRON', true ); to wp-config.php, above the line that says “stop editing”. Scheduled tasks now run from the cron job, not on page loads.
  • If a page waits on another service, such as a payment, shipping or social feed API, set a short timeout in the code so a slow reply cannot hold the page.

Fix a 504 from a CDN, DNS or firewall

Each server in the chain has its own time limit. A CDN waits a set time for your server, and PHP stops a script after max_execution_time. If PHP’s limit runs out first, you see a PHP error instead of a 504.

Cloudflare, for example, waits 100 seconds by default, then shows error 524, “A timeout occurred”. A longer PHP limit does not help once the CDN has given up, so make the page faster or move the work to a cron job.

  • Pause the CDN for the site, wait a few minutes and reload.
  • If the page loads slowly but fully, the CDN’s time limit is the cause. Make the page faster.
  • Find your server’s IP address in your welcome email or client area.
  • In the CDN’s DNS or origin settings, note the current records, so you can undo a change.
  • Check that the A records for the domain and for www point to that IP address. Fix any old or mistyped address.
  • In cPanel, open IP Blocker and remove any block on the CDN’s IP ranges. The CDN publishes its list.
  • Check any security plugin or firewall app on the site for blocks on the CDN.
  • If the CDN connects to your server over HTTPS, open SSL/TLS Status in cPanel and check that the domain has a valid certificate.
  • If the server’s own firewall may be blocking the CDN, ask your host. Give the time of the error and the CDN’s name.
  • Turn the CDN back on when you are done.

HostUpIndia Web & cPanel Hosting

HostUpIndia Web & cPanel Hosting runs on LiteSpeed with NVMe storage, so the LiteSpeed Cache plugin works on WordPress sites, and each plan card lists its CPU and RAM. Every plan includes cPanel for the steps above, terminal (SSH) access, free SSL and daily backups kept 30 days.

Plans start at ₹49 a month on 3-year billing. Prices exclude 18% GST. See Web & cPanel plans.

  • Moving from another host? The in-house team moves your site for you: free website migration.
  • Support tickets and email are received 24 hours a day, 7 days a week; WhatsApp is open for questions from 10 am to 7 pm IST, Monday to Saturday.
  • More help guides.