Enabling HTTP/2 on Apache improves page load performance by allowing multiple requests to share a single connection (multiplexing) and by reducing overhead through header compression. The biggest wins show up on sites with many small assets, where fewer round trips means faster rendering and fewer “waiting on the network” moments.
In Apache HTTP Server, HTTP/2 support is provided by mod_http2 (available in Apache 2.4.17 and newer). For HTTPS, the protocol is typically negotiated during the TLS handshake using ALPN, selecting h2 while keeping http/1.1 available for legacy clients. For cleartext connections, h2c uses an HTTP/1.1 Upgrade mechanism when explicitly allowed.
Most web browsers require HTTP/2 over TLS, so enabling h2 on port 443 is the common production setup; h2c is mainly useful for backend clients, proxies, and specialized use cases. Configuration changes should be syntax-tested before restarting to avoid an outage, and older TLS stacks without ALPN support can prevent HTTP/2 negotiation even when the module is loaded.
Steps to configure HTTP/2 for Apache:
- Open a terminal session with sudo privileges.
$ whoami user
- Verify that your server is running Apache version 2.4.17 or newer.
$ apache2ctl -v Server version: Apache/2.4.58 (Ubuntu) Server built: 2025-08-11T11:10:09
Use httpd -v on distributions that do not ship apache2ctl as the primary control script.
- Enable http2 module for Apache.
$ sudo a2enmod http2 Enabling module http2. To activate the new configuration, you need to run: systemctl restart apache2
- Distributions with a2enmod support enable the module without editing module load files by hand.
- Distributions without a2enmod typically load the module via a LoadModule line such as LoadModule http2_module modules/mod_http2.so in the module configuration directory.
- If enabling fails because the module is missing, the installed Apache build may not include mod_http2, or it may be shipped as a separate package.
Item Debian/Ubuntu/openSUSE Fedora/RHEL/CentOS Module enablement a2enmod http2 Ensure LoadModule http2_module modules/mod_http2.so is present Service name apache2 httpd - Confirm that mod_http2 appears in the loaded module list.
$ sudo apache2ctl -M | grep http2 http2_module (shared)
No output indicates the module is not loaded in the active configuration.
- Open the configuration file for your Apache website using your preferred text editor.
$ sudo vi /etc/apache2/sites-available/host.example.net.conf
On Debian/Ubuntu-style layouts, active sites are usually enabled via symlinks under /etc/apache2/sites-enabled/.
- Add relevant Protocols directive in main Apache configuration file or on a specific virtual server configuration.
<VirtualHost *:80> Protocols h2c http/1.1 </VirtualHost> <VirtualHost *:443> Protocols h2 http/1.1 </VirtualHost>
h2 is the common browser-facing choice on TLS (port 443), while h2c is mainly for cleartext upgrade-capable clients and internal traffic.
Related: Configuration options for HTTP/2
HTTP/2 requires a threaded MPM (event or worker). If mpm_prefork is active (often due to libapache2-mod-php), switch to PHP-FPM and enable mpm_event before expecting h2 to negotiate.
- Save the configuration file.
Invalid directives can prevent Apache from restarting cleanly, causing downtime until the configuration is corrected.
- Test the Apache configuration for syntax errors before restarting.
$ sudo apache2ctl -t Syntax OK
- Restart Apache to apply the changes.
$ sudo systemctl restart apache2 $ sudo systemctl restart httpd
The correct unit name depends on the distribution, and only one of the commands applies to a given host.
- Check that HTTP/2 is enabled by examining the server response headers.
$ curl --http2 -sI https://host.example.net/ HTTP/2 200 last-modified: Sat, 10 Jan 2026 05:32:07 GMT etag: "29af-64801f6762249" accept-ranges: bytes content-length: 10671 vary: Accept-Encoding content-type: text/html date: Sat, 10 Jan 2026 12:11:39 GMT server: Apache/2.4.58 (Ubuntu)
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
