HTTP/2 over TLS reduces per-page request latency by multiplexing many parallel requests over a single connection and by header compression. Apache 2.4 ships mod_http2, which makes the upgrade a module enable plus a one-line vhost change — assuming the rest of the stack does not fight it. This article is the enable procedure plus the operational subtleties: MPM choice, PHP-FPM compatibility, the request-body memory cost, and the protocols-list ordering that controls negotiation.
How to verify
Confirm the module is loaded and whether HTTP/2 is currently negotiated:
apachectl -M | grep -E 'http2|ssl'
sudo apache2ctl -t -D DUMP_RUN_CFG | grep -i protocols
curl -sI --http2 https://example.com/ | head -3
openssl s_client -connect example.com:443 -servername example.com -alpn h2,http/1.1 </dev/null 2>/dev/null | grep -i 'ALPN'
The curl line outputs HTTP/2 200 if HTTP/2 is negotiated. The openssl line shows whether h2 was selected via ALPN — if it lands on http/1.1, ALPN is misconfigured.
What’s happening
HTTP/2 is a binary multiplexed protocol that runs over the same TLS connection a browser opens to your site. The negotiation is via ALPN (Application-Layer Protocol Negotiation) — the client offers h2, http/1.1 in the TLS handshake, the server picks the highest it supports. mod_http2 implements h2 on top of mod_ssl.
The Protocols directive declares which protocols the vhost (or globally) is willing to serve. Order matters — the first match in the client’s preference list wins. The standard line:
Protocols h2 http/1.1
Two MPM rules:
- HTTP/2 requires a threaded MPM —
mpm_eventormpm_worker. Notmpm_prefork. The protocol’s worker threads cannot live in a process-per-connection model. mod_phpforces prefork, which blocks HTTP/2. The only path forward is moving PHP to PHP-FPM and switching to event (see PHP-FPM proxy).
Once enabled, every TLS connection where ALPN selects h2 flows through mod_http2’s worker threads. The vhost continues to see the same request lines, headers, and URI shapes as HTTP/1.1 — HTTP/2 is invisible to most application code.
The procedure
-
Confirm the MPM is event or worker, not prefork.
apachectl -M | grep mpmIf the answer is
prefork_module, deal with that first. See MPM event vs prefork. -
Enable the module.
sudo a2enmod http2 sudo apache2ctl configtest sudo systemctl restart apache2A restart, not a reload, is required when adding the
http2module — the protocol handler needs to bind during startup. -
Declare the protocols in the vhost. For HTTPS vhosts, add inside the
<VirtualHost *:443>block:Protocols h2 http/1.1To declare globally, put the line in
/etc/apache2/apache2.confor/etc/apache2/conf-enabled/protocols.conf. -
For HTTP-only vhosts. HTTP/2 over cleartext (
h2c) is supported but unused by browsers — they only speakh2over TLS. If you need to test it fromcurl:# In a port-80 vhost (rarely useful, here for completeness) Protocols h2c http/1.1The realistic answer is: HTTP/2 is for the 443 vhost. The 80 vhost redirects to 443.
-
Configtest, reload (or restart if first enable).
sudo apache2ctl configtest sudo systemctl reload apache2 -
Verify negotiation. From the local box and from outside:
curl -sI --http2 https://example.com/ curl -sI https://example.com/ | grep -i 'HTTP/'The headline status line should read
HTTP/2 200. Browsers’ developer tools show the protocol in the Network panel. -
Tune the connection limits for HTTP/2. The defaults are conservative. For sites that legitimately use many parallel requests:
H2MaxSessionStreams 100 H2MaxWorkers 20 H2MinWorkers 10 H2StreamMaxMemSize 65536H2MaxSessionStreamscaps concurrent streams per connection (default 100).H2MaxWorkers/H2MinWorkersset the worker thread pool that processes H2 streams. Match the worker pool to your traffic.
Common pitfalls
- A vhost without
Protocols h2 http/1.1falls back to HTTP/1.1 even when the module is loaded — the declaration is per-vhost and required. - Browsers only negotiate
h2over TLS. Plaintext HTTP/2 (h2c) is for curl and some internal services; do not expect it to help end-user latency. - Behind a reverse proxy or CDN that terminates TLS, the protocol between client and proxy is determined by the proxy, not Apache; Apache and the proxy can speak HTTP/1.1 to each other while the public connection is HTTP/2.
mod_proxydoes not forward HTTP/2 upstream by default;mod_proxy_http2is the workaround, rarely worth the complexity. HTTP/1.1 with keepalive to the upstream is the standard pattern.- Large request bodies (uploads) under HTTP/2 require Apache to buffer per-stream — set
H2StreamMaxMemSizeconsciously if uploads are a substantial part of the traffic.
Stack Harbor enables HTTP/2 by default on every Apache front we manage that meets the prerequisites (event MPM, PHP-FPM if applicable, current TLS config). For boxes that cannot make the jump because they are pinned to mod_php or old PHP versions, the migration plan to PHP-FPM + event + HTTP/2 is a standard scope of work under Managed Operations.