Why am I getting an HTTP 504 gateway timeout with Apache 2.4.6?

Why am I getting an HTTP 504 gateway timeout with Apache 2.4.6?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why am I getting an HTTP 504 gateway timeout with Apache 2.4.6?

You are encountering a classic infrastructure bottleneck: your backend process finishes successfully, but the client receives an HTTP 504 Gateway Timeout. In your specific environment—CentOS 7 with PHP 5.6 and Apache 2.4.6—the root cause is not that Apache is dropping your request prematurely, but rather that the server has a hard-coded limit on how long it will wait for a backend script to execute before terminating the connection and sending the error response.

The standard Timeout directive in Apache configuration files typically caps at 60 seconds. While modern versions of Apache (2.4.5+) allow you to increase this value via the ModSecurity, mod_proxy, or specific MPM settings, Apache 2.4.6 has a known limitation where it cannot handle timeouts exceeding 60 seconds for certain request types, particularly when processing long-running PHP scripts without external proxy modules. This means that regardless of how you configure your httpd.conf or .htaccess files to set a higher timeout value, the underlying architecture of this specific version will revert to the 60-second ceiling.

The technical behavior here is straightforward: Apache acts as the gateway. It initiates the request to your PHP script (likely via FastCGI or mod_php). While the PHP process runs in the background on the server and eventually produces output, Apache's internal timer triggers a SIGTERM signal to the connection if it hasn't received data from the backend within 60 seconds. At that exact moment, Apache closes the socket and sends the 504 Gateway Timeout header to the client. The PHP process might have already finished writing its HTML or JSON response to stdout, but the HTTP transaction is already dead to the client.

To resolve this on Apache 2.4.6 without upgrading the web server immediately, you must address the timeout at the application logic level rather than trying to force a configuration change that the software version will reject. The most reliable approach is to optimize your PHP execution time. Since you cannot rely on increasing the Apache Timeout directive beyond 60 seconds, you need to ensure that heavy operations—such as large dataset processing, complex database queries, or external API calls—are handled asynchronously or are broken into smaller chunks.

If your application logic requires a process that inherently takes longer than 60 seconds, simply increasing the PHP execution timeout (max_execution_time) in php.ini will not help if Apache is the one enforcing the 60-second cap on the TCP connection. You must restructure the workflow. A common pattern involves using AJAX to break down long tasks or offloading heavy computation to a separate worker process that communicates via message queues (like RabbitMQ) or a dedicated background job system. This ensures the HTTP response is sent within the 60-second window, even if the actual data processing takes minutes.

If you are unable to modify the application logic immediately, you may consider switching from mod_php to mod_fcgid combined with external process managers like PHP-FPM. While this does not inherently bypass the Apache 2.4.6 timeout limit, it provides better visibility into where the request is stalling. You can then use tools like strace or monitoring agents to see if the hang occurs in a specific system call within your PHP code.

For new deployments, upgrading from Apache 2.4.6 to a later version (such as 2.4.39 or 2.4.50+) is highly recommended. Newer versions have patched many of the timeout handling quirks found in older releases and offer more granular control over connection pooling and keepalive settings. Additionally, if your stack allows it, migrating to Nginx as the front-end reverse proxy (handling static assets and short-lived requests) while keeping Apache or PHP-FPM on the back-end can provide much more flexible timeout configurations, often allowing timeouts of several minutes or even hours depending on the specific configuration of the backend.

Our network