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
- Find the slow operation first — enable PHP-FPM slowlog (
slowlog = /var/log/php-fpm/$pool-slow.logandrequest_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). - 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.
- Align the timeouts — once the real fix is in, set
Timeout(Apache) andProxyTimeout(mod_proxy) higher thanmax_execution_time(PHP) higher thanrequest_terminate_timeout(PHP-FPM). The shortest one will fire first; keep it in PHP-FPM so the response is consistent. - For LiteSpeed —
lsadmpanel: General > Tuning > Max Keep-Alive Requests and Connection Idle Timeout. Per-vhost can override via.htaccesswithLSAPI_TIMEOUT. - 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.