HTTP/2 and HTTP/3 with Apache

HTTP/2 in Apache is one line of configuration, provided the right process model is running. That is where it usually fails. Apache still cannot do HTTP/3; you need a helper in front for that.

Requirements

Switch from prefork to event

prefork is usually only active because mod_php requires it. The solution is PHP-FPM: PHP runs as its own service and Apache passes requests on. On Debian and Ubuntu (adjust the PHP version):

sudo apt install php8.3-fpm
sudo a2dismod php8.3 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi setenvif http2
sudo a2enconf php8.3-fpm
sudo systemctl restart apache2

On RHEL, Rocky and Alma event is already the default. Check the model with apachectl -V | grep -i mpm.

Turn on HTTP/2

One line, globally in the main configuration or in the respective <VirtualHost *:443>:

Protocols h2 http/1.1

# optional: HTTP/2 without TLS (h2c), only for internal services behind a proxy
# Protocols h2 h2c http/1.1

# no browser uses server push any more, Chrome removed it
H2Push off

Then apachectl configtest and systemctl reload apache2.

Test

curl -sI --http2 https://www.example.com -o /dev/null -w '%{http_version}\n'
# output 2 = HTTP/2 active

Without a command line, use the HTTP/2 & HTTP/3 check. If it still says 1.1, check the MPM, whether mod_http2 is loaded (apachectl -M | grep http2) and whether the Protocols line is in the right vhost.

And HTTP/3?

HTTP/3 runs over QUIC on UDP. Apache httpd still does not support it, not even with add-on modules in the official package. If you want HTTP/3, put something in front that speaks QUIC:

For most sites HTTP/2 already brings most of the gain. HTTP/3 helps mainly on mobile and changing networks.

FAQ

Do I need HTTP/2 between the proxy and Apache too?

No. If nginx, HAProxy or a CDN in front terminate TLS, HTTP/1.1 internally is enough. The gain happens on the way to the visitor.

Does .htaccess still work after switching to PHP-FPM?

Yes. .htaccess is an Apache feature, not mod_php. Only php_value lines in .htaccess no longer work with PHP-FPM; they belong in the pool configuration or a .user.ini.

How do I enable HTTP/2 at my web host?

Not yourself. On shared hosting the host decides. Most have offered HTTP/2 for a long time; the check shows you.

Sources and documentation