A 502 means your web server got a bad response from PHP. A 504 means PHP took too long and the server gave up waiting. Neither error comes from WordPress itself – they happen at the server infrastructure layer, before WordPress loads. That makes them harder to diagnose than plugin conflicts but the causes are usually one of three things: the server is overloaded, PHP crashed, or a specific script is running too long.
What Causes 502 and 504 Errors
502 Bad Gateway means the server (usually Nginx) tried to communicate with a backend process (PHP-FPM, Apache, or an upstream server) and received an invalid or corrupted response. Causes: PHP-FPM has crashed, the PHP process is overloaded and returning garbage, or there is a misconfiguration between the web server and PHP.
504 Gateway Timeout means the server waited for the backend too long and gave up. Causes: a PHP script is taking too long to execute (a slow database query, a file operation, an API call that is not responding), PHP-FPM is overloaded with too many concurrent requests, or the server lacks resources to handle current traffic volume.
Step 1: Check If It Is a Temporary Overload
Reload the page several times. If the error appears intermittently (sometimes works, sometimes 504), the server is being overloaded at peak times rather than fundamentally broken. Check your server’s CPU and memory usage in your hosting control panel. A traffic spike, a scheduled task running at that moment, or a backup process can briefly exhaust resources. If the error is intermittent, the solution is either better hosting or performance optimisation to reduce server load.
Problem not solved? Describe the issue and get a free estimate.
Step 2: Check PHP Error Logs
A 502/504 that persists points to a specific PHP problem. Check your PHP-FPM error log. Location varies by server setup – typically at /var/log/php-fpm/error.log or accessible through your hosting control panel’s log viewer. Look for messages like: “max_children reached”, “pool www is full”, or “terminated due to unterminated request”. These messages reveal whether PHP-FPM is crashing or being overwhelmed.
Step 3: Increase PHP Timeout
If 504 errors occur on specific pages (admin pages that run long processes, WooCommerce import pages, bulk update operations), the PHP execution is timing out. Increase the timeout limit. Add to .htaccess:
php_value max_execution_time 300
Or in wp-config.php:
set_time_limit(300);
300 seconds (5 minutes) is sufficient for most long-running WordPress operations. If your host does not allow .htaccess PHP settings, request the increase through your hosting support.
Step 4: Deactivate Recently Installed Plugins
A plugin that runs an expensive operation on every page load (a broken analytics plugin making HTTP requests, a plugin with an infinite loop) can cause consistent 504 timeouts. If 502/504 errors started after installing a specific plugin, that plugin is the likely cause. Deactivate it via FTP (rename its folder in wp-content/plugins/) and test if the error resolves.
Step 5: Contact Your Host
If the above steps do not resolve 502/504 errors, the issue is at the server infrastructure level – PHP-FPM configuration, server resource limits, or network issues between components. Your hosting provider needs to diagnose and fix these. When contacting support, provide: the exact error message, the time the error occurs, whether it is consistent or intermittent, and any recent changes (plugin updates, traffic increases, new functionality).
Managed WordPress hosts (WP Engine, Kinsta, Cloudways) typically diagnose and fix 502/504 errors faster than shared hosting support because their support teams are WordPress-specific and have direct server access.
WP-Cron as a Hidden 504 Cause
WordPress Cron (WP-Cron) triggers scheduled tasks on page load rather than on a real server schedule. On a busy site, several cron tasks can fire simultaneously – backups, email sends, cache rebuilds – creating a brief but severe server load spike that produces 504 errors. If your 504s occur at predictable intervals (every hour, daily at the same time), WP-Cron is likely the cause.
Disable WP-Cron from running on every page load by adding to wp-config.php:
define( 'DISABLE_WP_CRON', true );
Then set up a real server cron job through your hosting control panel to trigger WordPress cron instead. Add a cron job that runs every 5 minutes:
*/5 * * * * wget -q -O - https://yoursite.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
This offloads cron execution to a proper scheduled task rather than piggybacking on visitor page loads, which eliminates cron-caused 504 spikes entirely.