How to Fix WordPress 504 Gateway Timeout Error on Hostinger

by Fahim

When Hostinger throws a 504 Gateway Timeout, it means the front-facing web server (LiteSpeed or Nginx) waited for an upstream PHP process to finish, gave up, and cut the connection. The server itself isn’t dead—something in your WordPress stack is taking way too long to finish. Here is how I track down the bottleneck and fix it in hPanel.

Server rack status lights indicating network and gateway timeout troubleshooting
Server rack status lights indicating network and gateway timeout troubleshooting

Understanding Why Hostinger Throws a 504 Gateway Timeout

When someone visits your site, Hostinger’s edge server passes the request back to PHP (typically LiteSpeed’s lsphp or PHP-FPM). If that PHP worker takes longer than the server’s timeout window—usually 30 to 60 seconds on shared plans—the edge server drops the connection and returns an HTTP 504 Gateway Timeout status code.

In almost every case I’ve fixed on Hostinger, the culprit was one of these:

  • A PHP script hit its max_execution_time limit during a heavy background task.
  • A plugin tried to make an external API call to a server that hung or never responded.
  • The database locked up on a slow query or bloated table.
  • Default WP-Cron fired during a traffic spike and starved the remaining PHP workers.
  • Cloudflare or another CDN proxy timed out before Hostinger finished rendering the HTML.

Step 1: Increase PHP Execution Time and Memory Limits in hPanel

First, give your scripts a little breathing room so you can at least load the site and troubleshoot without hitting an instant cutoff.

Head to hPanel, go to Advanced > PHP Configuration, click the PHP Options tab, and bump your limits.

These baseline settings usually keep long-running processes from getting killed prematurely:

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

If you prefer editing files directly or want to configure this globally, check out our guide to increase WordPress PHP memory limit and max upload size in Hostinger.

Next, make sure LiteSpeed isn’t severing connections early. Drop this rule at the very top of your .htaccess file via hPanel’s File Manager or SSH:

# Prevent LiteSpeed connection aborts
 RewriteEngine On RewriteRule .* - [E=noconntimeout:1] RewriteRule .* - [E=noabort:1]

The noconntimeout directive tells the LiteSpeed web server to let your backend PHP scripts finish running instead of cutting them off at the proxy layer.

Step 2: Isolate Hanging Plugins and Faulty Themes via WP-CLI

If raising your execution limit just turns a 30-second 504 into a 300-second 504, a script is definitely hanging. The fastest way to find the offending plugin is with WP-CLI over SSH.

SSH into your Hostinger account and head to your document root:

cd ~/domains/yourdomain.com/public_html

Disable all plugins in one shot to see if the timeout disappears:

wp plugin deactivate --all

Reload the site in your browser. If it pops up instantly, turn your plugins back on one by one until you hit the timeout again:

wp plugin activate woocommerce
wp plugin activate litespeed-cache

The usual suspects here are security plugins running aggressive live file scans, broken sitemap generators, or marketing add-ons waiting on dead third-party webhooks.

Step 3: Enable WordPress Debug Logging to Catch Hanging Requests

If the 504 is intermittent and only hits certain pages, WordPress debug logging will show you where PHP got stuck before the server closed the socket.

Open your wp-config.php and add these lines right 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 tail the log file directly in your terminal:

tail -n 50 wp-content/debug.log

If you need deeper visibility into database queries or remote requests, the official WordPress Debugging Documentation covers query logging and hook tracking.

Step 4: Offload Default WP-Cron to a Real System Cron Job

WordPress runs its built-in cron system by checking for scheduled tasks on every page load. If a visitor lands on your site and triggers a backlog of scheduled posts, backups, or WooCommerce action scheduler queues, their browser session will hang until the server drops the connection.

First, kill the default web-based cron in wp-config.php:

define('DISABLE_WP_CRON', true);

Next, set up a real system cron job in hPanel under Advanced > Cron Jobs. Set it to run every 15 minutes with this command:

/usr/bin/php /home/u123456789/domains/yourdomain.com/public_html/wp-cron.php >/dev/null 2>&1

For a complete breakdown of setting this up, read our full walkthrough on how to replace WordPress WP-Cron with a real cron job in Hostinger.

Step 5: Check Database Contention and Slow Query Locks

Bloated transient rows or table locks on massive tables like wp_options or wp_actionscheduler_actions will tie up PHP workers until they time out.

Run a quick table repair and clear expired transients with WP-CLI:

# Optimize and repair all database tables
wp db repair
wp db optimize # Purge expired transients from wp_options
wp transient delete --expired

Next, check your autoloaded data size in MySQL. If autoloaded data exceeds 1MB, every single PHP request has to drag that payload into memory before executing:

wp db query "SELECT SUM(LENGTH(option_value)) / 1024 / 1024 AS autoload_size_mb FROM wp_options WHERE autoload = 'yes';"

If your autoload size is climbing past 1.5MB, query for the biggest entries so you can clean out leftover plugin junk:

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

Step 6: Adjust CDN and Proxy Edge Timeouts

If your site sits behind Cloudflare, the 504 screen might be coming from Cloudflare’s edge rather than Hostinger.

Cloudflare’s free plan has a hard 100-second edge timeout. If an uncached, database-heavy checkout or export takes 101 seconds, Cloudflare serves a 504 even if Hostinger was milliseconds away from returning the rendered page.

Here is how to check your edge setup:

What I Ran: Pinpointing a Frozen cURL Request

I ran into a stubborn 504 on a client’s WooCommerce site running on Hostinger Business hosting. The homepage loaded in a snappy 420ms, but checkout cart pages consistently timed out at exactly 60.01 seconds.

To see what was hanging, I dropped a quick hook into the active child theme’s functions.php to log external HTTP transport times across the site:

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);

Hitting the cart page immediately logged this in wp-content/debug.log:

[08-Mar-2025 14:12:08 UTC] HTTP Request Failed: https://api.abandoned-plugin-service.com/v1/verify | Error: cURL error 28: Operation timed out after 60001 milliseconds with 0 bytes received

An outdated abandoned cart tracking plugin was firing a synchronous cURL request to a defunct API server on every cart load. Because the plugin used a 60-second timeout with no fallback, the PHP worker sat completely frozen until LiteSpeed gave up and served a 504. Nuking that single plugin fixed the issue on the spot.

Frequently Asked Questions

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

A 502 Bad Gateway means the upstream server (like PHP or MySQL) crashed, rejected the connection, or returned an unreadable response. A 504 Gateway Timeout means the upstream server accepted the request, but took too long to complete it, so the proxy severed the connection.

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

Yes. If your account hits its CloudLinux CPU or memory limits in hPanel (check under Order Usage), Hostinger throttles your PHP execution speed. Tasks that normally take 2 seconds can crawl to 30+ seconds and hit the gateway timeout.

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

Demo importers download dozens of images and run hundreds of SQL inserts in a single request, which easily blows past standard PHP timeout limits. Setting max_execution_time to 300 and adding the LiteSpeed noconntimeout rule in .htaccess will give the importer enough time to finish.

Does clearing the LiteSpeed Cache plugin resolve a 504 error?

Purging cache helps if a 504 error page was accidentally cached by a CDN or reverse proxy. But if the underlying page request is still hitting an infinite loop or locked database table, clearing the cache won’t solve the real problem.

Next Steps to Keep Your Hostinger Stack Stable

Once your site is back up, take the time to clean up your autoloaded database records and offload object caching so background operations don’t bottleneck your traffic. Set up in-memory caching using our step-by-step tutorial on how to configure Redis Object Cache on Hostinger for faster WordPress performance.

all_in_one_marketing_tool