HTTP/2 is an updated version of HyperText Transfer Protocol that improves web performance through multiplexing, header compression, and more efficient data transfers. It reduces latency and enhances page load speeds, resulting in quicker response times for end users. Support for modern encryption, such as TLS with ALPN, ensures secure and optimized communication between client and server.
Enabling HTTP/2 in Apache requires the mod_http2 module, introduced in version 2.4.17, along with compatible system dependencies and potential updates to OpenSSL for encrypted connections. Loading the correct modules and enabling them in the server configuration allows Apache to handle both plain and secure HTTP/2 traffic, identified by h2c and h2 protocols, respectively. Proper version checks and module loading ensure compliance with modern security standards and the best possible performance.
Configuration changes involve updating Apache directives to accommodate multiplexed streams and advanced flow control. Administrators can set up the server to accept HTTP/2 requests while still serving legacy HTTP/1.1 connections. Verifying these settings is critical for maintaining a performant and stable hosting environment.
Steps to configure HTTP/2 for Apache:
- Launch terminal.
- Verify that your server is running Apache version 2.4.17 or newer.
$ apachectl -v Server version: Apache/2.4.46 (Unix) Server built: Jul 1 2020 09:13:15
This command outputs the version of your Apache server. Ensure it's 2.4.17 or newer.
Use httpd -v if you're using CentOS or other Red hat variants.
- Enable http2 module for Apache.
$ sudo a2enmod http2 # Ubuntu, Debian and SUSE Enabling module http2. To activate the new configuration, you need to run: systemctl restart apache2
- Distribution with a2enmod support can simply run the command above without having to manually enable the required modules.
- Fedora, CentOS and Red Hat enables the module by default so requires no manual action to enable the modules.
Options Debian, Ubuntu openSUSE and SLES Fedora Core, CentOS, RHEL macOS homebrew xampp a2enmod support yes yes no no no no Modules to install none Module name n/a http2 Loadmodule directive n/a LoadModule http2_module <module_locations>/mod_http2.so - Open the configuration file for your Apache website using your preferred text editor.
$ sudo vi /etc/apache2/sites-available/000-mysite.conf
- Add relevant Protocols directive in main Apache configuration file or on a specific virtual server configuration.
<VirtualHost *:80> # ..... # .... Protocols h2 h2c http/1.1 </VirtualHost>
Related: Configuration options for HTTP/2
- Restart Apache to apply the changes.
$ sudo systemctl restart apache2 # Ubuntu and Debian $ sudo systemctl restart httpd # CentOS and Red Hat
- Check that HTTP/2 is enabled by examining the server response headers.
$ curl --http2 --head www.simplified.guide HTTP/1.1 101 Switching Protocols Upgrade: h2c Connection: Upgrade HTTP/2 200 date: Sun, 00 Jan 1900 00:00:00 GMT server: Apache/2.4.41 (Ubuntu) last-modified: Sat, 08 Feb 2020 14:15:13 GMT etag: W/"2aa6-59e11227347f6" accept-ranges: bytes content-length: 10918 vary: Accept-Encoding content-type: text/html

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.
Comment anonymously. Login not required.