HTTP/2 is a significant improvement over HTTP/1.1, especially in the speed department. Apache supports HTTP/2 though it's disabled by default.

You can enable HTTP/2 for Apache by installing the http2 module and configuring Apache to serve requests using HTTP/2 instead of the default HTTP/1.1.

Steps to enable HTTP2 on Apache:

  1. Launch terminal application.
  2. 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>/
  3. Add relevant Protocols directive in main Apache configuration file or on a specific virtual server configuration.
    <VirtualHost *:80>
            # .....
            # ....
            Protocols h2 h2c http/1.1
  4. Restart Apache service for the changes to take effect.
    $ sudo systemctl restart apache2 #Ubuntu and Debian
    $ sudo systemctl restart httpd # CentOS and Red Hat
  5. Test by accessing the service using curl.
    $ curl --http2 --head
    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
Discuss the article:

Comment anonymously. Login not required.