Skip to content

HTTP 504 Gateway Timeout on cPanel: long PHP, mod_proxy, upstream

A 504 on cPanel means the upstream took longer to respond than the front-end was willing to wait. The fix lives in three timeout settings, not the application.

A 504 Gateway Timeout on cPanel is a story about which timer ran out first. The application might have been ready to finish the request, but Apache, LiteSpeed, mod_proxy, or PHP-FPM gave up before it could. Fixing a 504 by raising every timeout to 600 seconds is a tempting trap — it hides the actual slow query or external API call that needs the real fix.

What’s happening

A request crosses at least three timeouts: the web server’s request timeout, the proxy timeout to the upstream, and the upstream worker’s own execution limit. PHP also has its own max_execution_time. If any of these fires before the response, the request becomes a 504. Identifying which timer fired requires reading the error logs with timestamps lined up against the request.

How to verify

Find the slow request and the timer that killed it:

# Apache error log with timeout entries
tail -200 /usr/local/apache/logs/error_log | grep -E "Timeout|timed out"
# LiteSpeed gateway timeout
tail -200 /usr/local/lsws/logs/error.log | grep -i timeout
# PHP-FPM slowlog (if enabled)
tail -100 /opt/cpanel/ea-php82/root/var/log/php-fpm/<user>-slow.log
# current values
grep -i timeout /etc/apache2/conf.d/includes/pre_main_global.conf
grep ^request_terminate_timeout /opt/cpanel/ea-php82/root/etc/php-fpm.d/<user>.conf
grep ^max_execution_time /opt/cpanel/ea-php82/root/etc/php.ini

The fix

  1. Find the slow operation first — enable PHP-FPM slowlog (slowlog = /var/log/php-fpm/$pool-slow.log and request_slowlog_timeout = 5s). Restart the pool. Look at the stack traces — they point to the actual bottleneck (usually a database query or an external API call).
  2. Fix the slow operation — index the query, add a cache, move the external call to a queue worker. A 60-second user-facing request is a bug, not a timeout setting.
  3. Align the timeouts — once the real fix is in, set Timeout (Apache) and ProxyTimeout (mod_proxy) higher than max_execution_time (PHP) higher than request_terminate_timeout (PHP-FPM). The shortest one will fire first; keep it in PHP-FPM so the response is consistent.
  4. For LiteSpeed — lsadm panel: General > Tuning > Max Keep-Alive Requests and Connection Idle Timeout. Per-vhost can override via .htaccess with LSAPI_TIMEOUT.
  5. Long-running endpoints — if a route legitimately runs 5+ minutes (report generation), move it to a background job. The browser cannot wait that long without retrying.

A 504 that hits only POST requests is usually a LimitRequestBody or an upstream timeout on body-uploading. Stack Harbor profiles slow endpoints under cPanel server administration — start a conversation when 504s have a request pattern.