How to Fix WordPress 504 Gateway Timeout Error on Hostinger

by Fahim Mahmud Chisti

A WordPress 504 Gateway Timeout on Hostinger means the web server (LiteSpeed) waited for a PHP request to finish, gave up and closed the connection. The server is still up; something in your WordPress site is taking too long. By the end of this guide you will know which plugin, query, scheduled task or external request is hanging, and how to stop it.

Quick answer: A 504 on Hostinger means one PHP request ran longer than the server would wait. Give PHP more time so you can work, then find and remove whatever is hanging.

  1. Raise max_execution_time in hPanel’s PHP Configuration.
  2. Deactivate all plugins with WP-CLI, then re-enable them one at a time.
  3. Turn on debug logging and read wp-content/debug.log.
  4. Replace WP-Cron with a real cron job.
  5. Delete expired transients and shrink oversized autoloaded options.
  6. If you use Cloudflare, test with the proxy switched off.
In this guide
  1. Before You Start
  2. What a 504 Gateway Timeout Means on Hostinger
  3. Step 1: Raise PHP Time and Memory Limits in hPanel
  4. Step 2: Find the Plugin That Hangs
  5. Step 3: Turn On Debug Logging to See Where PHP Stops
  6. Step 4: Move WP-Cron to a Real Cron Job
  7. Step 5: Clean Up Slow Database Tables and Autoloaded Options
  8. Step 6: Rule Out Cloudflare or Another CDN
  9. Step 7: Find an External Request That Never Answers
  10. If It Still Doesn’t Work
  11. Frequently Asked Questions
  12. Next Steps
Server rack status lights indicating network and gateway timeout troubleshooting

Before You Start

  • Access: your Hostinger hPanel login and SSH access to the hosting account (the WP-CLI steps run over SSH).
  • Time: about 20–45 minutes, depending on how many plugins you need to test.
  • Backup: take a fresh backup first. Steps 2 and 5 switch plugins off and rewrite database tables, so you want a way back.
  • Timing: deactivating plugins takes features such as checkout offline. Pick a quiet hour.

What a 504 Gateway Timeout Means on Hostinger

When someone visits your site, Hostinger’s web server passes the request to PHP (LiteSpeed’s lsphp on shared and cloud plans). If that PHP worker takes longer than the server’s timeout window, the web server drops the connection and returns an HTTP 504 Gateway Timeout status code.

The cause is almost always one of these:

  • A PHP script hit its max_execution_time limit (the longest a script may run) during a heavy task.
  • A plugin made an external API call to a server that hung or never answered.
  • The database got stuck on a slow query or a bloated table.
  • WP-Cron fired during a traffic spike and used up the PHP workers visitors needed.
  • A CDN such as Cloudflare timed out first. Cloudflare reports this as error 524, which is easy to mistake for a 504.

Step 1: Raise PHP Time and Memory Limits in hPanel

First, give your scripts more time so you can load the site and troubleshoot without an instant cutoff.

In hPanel, go to Advanced > PHP Configuration, open the PHP Options tab, and set these values:

max_execution_time = 300
max_input_time = 300
memory_limit = 512M
post_max_size = 128M
upload_max_filesize = 128M

Save the changes. To confirm they are live, open Tools > Site Health > Info in WordPress and expand Server. The PHP time limit should now read 300. If you prefer editing files directly, see our guide to increase the PHP memory limit and upload size on Hostinger.

Next, stop LiteSpeed from closing the connection early. Open .htaccess in your site’s public_html folder (with hPanel’s File Manager or over SSH) and add this block at the very top:

# Prevent LiteSpeed connection aborts
<IfModule Litespeed>
RewriteEngine On
RewriteRule .* - [E=noabort:1, E=noconntimeout:1]
</IfModule>

The noabort and noconntimeout flags tell the LiteSpeed web server not to abort a running PHP script or close the connection while the script is still working. Your plan’s PHP execution limit still applies.

Save the file and reload your site. If every page now shows a 500 Internal Server Error, the block was pasted incorrectly; remove it and try again.

Step 2: Find the Plugin That Hangs

If a higher limit just turns a 30-second 504 into a 300-second 504, a script is stuck rather than slow. The fastest way to find it is WP-CLI, WordPress’s command-line tool, over SSH.

Connect to your Hostinger account over SSH and move to the site’s document root (the folder that contains wp-config.php):

cd ~/domains/yourdomain.com/public_html

Replace yourdomain.com with your domain. To check WP-CLI can see the site, run wp core version; it should print your WordPress version.

Save the list of active plugins so you know what to turn back on later:

wp plugin list --status=active --field=name > ~/active-plugins.txt

Now disable all plugins in one go:

wp plugin deactivate --all

WP-CLI prints a success line with the number of plugins it deactivated. Reload the page that timed out. If it now loads quickly, a plugin is the cause. Turn plugins back on one at a time, reloading the page after each, until the timeout returns:

wp plugin activate woocommerce
wp plugin activate litespeed-cache

The plugin you activated just before the 504 came back is the culprit. Delete its line from ~/active-plugins.txt, then reactivate everything else at once:

wp plugin activate $(cat ~/active-plugins.txt)

Common offenders are security plugins running live file scans, broken sitemap generators, and marketing add-ons waiting on dead third-party webhooks.

Step 3: Turn On Debug Logging to See Where PHP Stops

If the 504 is intermittent or only hits certain pages, the WordPress debug log shows where PHP got stuck before the server closed the connection.

Open wp-config.php in the site root and add these lines just above the /* That's all, stop editing! */ comment:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);

Trigger the 504 in your browser, then read the end of the log over SSH from the same folder:

tail -n 50 wp-content/debug.log

Look at the entries written at the time of the timeout. A fatal error saying the maximum execution time was exceeded, or repeated warnings from one plugin’s folder, points straight at the cause. For query logging and hook tracing, see the official WordPress Debugging Documentation.

When you are done, set WP_DEBUG back to false and delete debug.log. Anyone who guesses its URL can read it.

Step 4: Move WP-Cron to a Real Cron Job

WordPress checks for scheduled tasks on every page load. When tasks are due, it fires an extra background request to wp-cron.php. If that request works through a backlog of scheduled posts, backups or WooCommerce Action Scheduler jobs during a traffic spike, it ties up PHP workers your visitors need.

First, turn off the page-load trigger by adding this line to wp-config.php:

define('DISABLE_WP_CRON', true);

Then create a real cron job in hPanel under Advanced > Cron Jobs, set to run every 15 minutes, with this command (use your own account username and domain in the path):

/usr/bin/php /home/u123456789/domains/yourdomain.com/public_html/wp-cron.php

After the next run, wp cron event list should show next-run times moving forward instead of sitting in the past. For the full setup, read how to replace WP-Cron with a real cron job in Hostinger.

Step 5: Clean Up Slow Database Tables and Autoloaded Options

Bloated transient rows (temporary cached values) and locks on large tables such as wp_options or wp_actionscheduler_actions hold PHP workers until they time out.

Over SSH, in the site root, clear expired transients and optimize your tables:

# Purge expired transients from wp_options
wp transient delete --expired

# Optimize database tables (can take a while on large tables)
wp db optimize

The first command reports how many expired transients it removed. The second prints one line per table. On InnoDB tables it notes that it will “recreate + analyze” instead of optimize, which is normal.

Next, check the size of your autoloaded data, the options WordPress loads into memory on every request. Site Health starts warning at roughly 800KB. Change the wp_ table prefix if yours differs:

wp db query "SELECT ROUND(SUM(LENGTH(option_value)) / 1024 / 1024, 2) AS autoload_size_mb FROM wp_options WHERE autoload IN ('yes', 'on', 'auto', 'auto-on');"

The result is a single number in megabytes. If it is well past 0.8, list the biggest entries so you can find leftovers from old plugins:

wp db query "SELECT option_name, LENGTH(option_value) AS option_size FROM wp_options WHERE autoload IN ('yes', 'on', 'auto', 'auto-on') ORDER BY option_size DESC LIMIT 10;"

Option names usually start with the plugin’s name. Only remove rows that belong to plugins you have already uninstalled.

Step 6: Rule Out Cloudflare or Another CDN

If your site sits behind Cloudflare, the error may come from Cloudflare’s edge rather than from Hostinger.

Cloudflare waits about 100 seconds for your origin to respond, a limit only Enterprise plans can raise. When the origin takes longer, Cloudflare returns its own error 524, not a 504. A 504 normally comes from your origin server and Cloudflare simply passes it along.

To check your edge setup:

  • In Cloudflare DNS, temporarily switch the record from Proxied (Orange Cloud) to DNS Only (Grey Cloud) to test the origin directly. If the page loads without Cloudflare but fails with it, the problem is on the edge. Switch the proxy back on when you finish.
  • Add an object cache so database-heavy pages finish well under the timeout. On Business and Cloud plans, that is the Object Cache option in hPanel; on a VPS, follow our guide to configure Redis Object Cache on Hostinger.

Step 7: Find an External Request That Never Answers

A common pattern: most pages load quickly, but one page type (often cart or checkout) times out after the same number of seconds every time. That points to an external HTTP request that never gets an answer.

To see which request hangs, add this hook to the active child theme’s functions.php. It logs every failed external HTTP request to debug.log (debug logging from Step 3 must be on):

add_action( 'http_api_debug', function ( $response, $context, $class, $args, $url ) {
    if ( is_wp_error( $response ) ) {
        error_log( 'HTTP Request Failed: ' . $url . ' | Error: ' . $response->get_error_message() );
    }
}, 10, 5 );

Load the slow page, then check wp-content/debug.log. A hanging request looks like this example:

[01-Sep-2026 14:12:08 UTC] HTTP Request Failed: https://api.example.com/v1/verify | Error: cURL error 28: Operation timed out after 60001 milliseconds with 0 bytes received

An entry like this means a plugin is calling an API server that no longer responds, and waiting for it. With a 60-second timeout and no fallback, the PHP worker stays frozen until LiteSpeed gives up and serves a 504. Deactivate or replace the plugin that owns that URL, then remove the logging hook.

If It Still Doesn’t Work

  • The 504 continues with every plugin off. Switch to a default WordPress theme in Appearance > Themes. Also check wp-content/mu-plugins: must-use plugins stay active even after wp plugin deactivate --all.
  • Site Health still shows the old PHP time limit. Look for a php.ini or .user.ini file in public_html that sets its own lower value, and remove that line.
  • The error only appears during a theme demo import. Importers run many downloads in one request. See how to fix a theme demo import that fails or gets stuck.
  • The error returns at the same time every day. A scheduled task is the likely cause. Run wp cron event list and look for heavy hooks (backups, feed imports) due at that time.

Frequently Asked Questions

What is the difference between a 502 and a 504 error on Hostinger?

A 502 means PHP failed; a 504 means PHP was too slow. With a 502 Bad Gateway, the upstream process crashed, refused the connection or sent an unreadable response. With a 504 Gateway Timeout, it accepted the request but did not finish in time, so the web server closed the connection.

Can high CPU or RAM usage cause 504 errors on Hostinger?

Yes. If your account hits its CloudLinux CPU or memory limits (check the resource usage page for your plan in hPanel), Hostinger slows your PHP processes down. Tasks that normally take a couple of seconds can crawl until they hit the gateway timeout.

Why does my 504 error only appear when importing demo content?

Because a demo import does a lot of work in one request. Importers download dozens of images and run hundreds of database inserts, which easily exceeds standard PHP time limits. Setting max_execution_time to 300 and adding the LiteSpeed noconntimeout rule from Step 1 usually gives the importer enough time.

Does clearing the LiteSpeed Cache plugin fix a 504 error?

Only when a 504 page was cached by mistake. Purging the cache removes an error page that a CDN or reverse proxy stored. If the page itself still hangs on a stuck plugin or a locked table, clearing the cache will not solve the real problem.

Next Steps

Once the site loads again:

  1. Turn debug logging off and remove the HTTP logging hook from Step 7.
  2. Keep the real cron job running so scheduled tasks no longer compete with visitors.
  3. Check the autoload size again after cleaning up old plugin data.
  4. Turn on object caching: the Object Cache option in hPanel on Business and Cloud plans, or Redis Object Cache on a Hostinger VPS.
all_in_one_marketing_tool