HTTP/2 lets a browser send many requests over one connection at the same time, compresses headers and removes much of the overhead of HTTP/1.1. Apache supports it through mod_http2. Enabling HTTP/2 in Apache takes a few minutes, but there is one catch: it does not work properly with the prefork MPM.
Before you start
- Apache 2.4.24 or newer (
apachectl -v). - HTTPS working: browsers only use HTTP/2 over TLS.
- Root access. Background on the protocol: HTTP/2 and HTTP/3 explained.
Switch from prefork to event
mod_http2 refuses to serve h2 with prefork (it logs a warning and falls back to HTTP/1.1), because prefork can only handle one request per process. Check your MPM:
apachectl -V | grep -i mpmIf it says prefork, move PHP to PHP-FPM and enable event first. Full steps: Apache MPMs explained. In short, on Ubuntu:
sudo apt install php8.3-fpm
sudo a2dismod php8.3 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo a2enconf php8.3-fpmEnable mod_http2
- Ubuntu/Debian:
sudo a2enmod http2 - AlmaLinux/Rocky:
sudo dnf install mod_http2(often already installed; check/etc/httpd/conf.modules.d/10-h2.conf).
Set the Protocols directive
Add globally (e.g. /etc/apache2/conf-available/http2.conf, then a2enconf http2) or per vhost:
Protocols h2 http/1.1h2is HTTP/2 over TLS, negotiated with ALPN during the handshake.http/1.1stays as the fallback for old clients.- You can add
h2c(cleartext HTTP/2) for internal backends, but browsers never use it.
Check TLS settings
HTTP/2 blacklists old cipher suites. Use a modern configuration with TLS 1.2 and 1.3 and ECDHE + AES-GCM or ChaCha20 ciphers:
SSLProtocol -all +TLSv1.2 +TLSv1.3
SSLHonorCipherOrder offMore on this: TLS versions and cipher suites.
Restart and verify
sudo apachectl configtest && sudo systemctl restart apache2- From the command line:It should print
curl -sI --http2 https://example.com/ | head -1HTTP/2 200. - In Chrome or Firefox DevTools → Network, show the Protocol column: requests should show
h2. - Logs: add
%Hto your LogFormat to record the protocol per request.
Tuning notes
- Drop old HTTP/1.1 tricks: domain sharding and heavy file concatenation help less with HTTP/2, since requests are multiplexed.
- Server push:
H2Pushis deprecated and browsers have removed support. Use<link rel="preload">or 103 Early Hints instead (H2EarlyHints onin Apache 2.4.58+). - Keep-alive: HTTP/2 connections stay open between page views; event MPM handles this efficiently.
- HTTP/3: Apache does not serve HTTP/3 natively. Put a CDN in front, or use LiteSpeed, Nginx or Caddy if you need it.
Troubleshooting
- Still HTTP/1.1: prefork still active, Protocols missing in the HTTPS vhost, or an old OpenSSL without ALPN.
- Log warning "mpm_prefork ... h2 disabled": switch MPM.
- ERR_HTTP2_INADEQUATE_TRANSPORT_SECURITY: a weak cipher was negotiated. Update the cipher list.
FAQ: HTTP/2 in Apache
Does HTTP/2 make every site faster?
Pages with many assets benefit most. Single-file APIs see little difference.
Do I need to change my website code?
No. HTTP/2 is negotiated by the server and browser; the content is unchanged.
Is HTTP/2 on by default on cPanel hosting?
Yes on MdmHost, where LiteSpeed serves HTTP/2 and HTTP/3.
