How to Enable HTTP/2 in Apache

cPanel administrators can log into WebHost Manager (WHM) and enable HTTP/2 with EasyApache4 with a slider. Unmanaged server administrators don’t have that pretty graphical interface for this task, excluding maybe those using Webmin, Vesta Control Panel, or another system administration interface. 

Regardless, it is still a quick, straight-forward process to enable HTTP/2 support on Apache web servers. Below we’ll cover how to:

This article does not apply to NGINX servers.

How to Enable HTTP/2 on an Apache Server

  1. SSH into your server as the root user.
  2. Ensure you have Apache installed (Ubuntu/CentOS) and the version is at least 2.4. Otherwise, you’ll need to upgrade Apache.
    apachectl -v
  3. Ensure you have a valid SSL certificate installed on your server so you can use force secure (HTTPS) connections. If you need one, you can use the free Certbot Let’s Encrypt SSL application on Ubuntu 18.04.

    Unfortunately, snapd is not compatible with our Cloud Server Hosting at this time. Instead, install Certbot with PIP (Python Installs Packages).

  4. Enable the HTTP/2 Apache module:
    a2enmod http2
  5. Edit your Apache virtual host configuration file with your preferred text editor – e.g. Nano, Emacs, VIM, etc. If you have an SSL installed, the file should end with le-ssl. One of the following should work depending on your server environment:
    sudo nano /etc/apache2/sites-enabled/domainname-le-ssl.conf
    sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf
  6. Add the following text in the configuration file directly underneath <VirtualHost *:443>:
    Protocols h2 http/1.1
  7. Save changes.
  8. Restart Apache:
    apachectl restart

If you have issues configuring HTTP/2 at any time, you can always request technical support from our Managed Hosting team.

How to Verify HTTP/2 is Being Used

Once you have it implemented and you have met all the requirements, how do you tell if the page is actually using HTTP/2? There are few ways that you can tell by using browser developer tools or third party extensions. We will be showing a few examples using the Google Chrome browser, Mozilla FireFox browser, command line interface, and the KeyCDN HTTP/2 test tool.

Google Chrome Browser – Using the Inspect Option

  1. Open the website using HTTP/2 with your Google Chrome browser.
  2. Select Inspect
     

    Right-click on a page and then select Inspect.


     

  3. Click on NetworkA new window will open. In the menu, click on Network.
     

  4. Select Protocol You may have to wait a few seconds after clicking on Network for it to process. Once it finishes you’ll see several columns starting with Name. Right-click on any of the columns that appear. You will see a list of options appear. Make sure that Protocol is checked.
     

  5. Look for protocol being used When the Protocol column appears you should be able to see if HTTP/2 is being used. You may need to inspect a different part of the page to see the HTTP/2 requests.
     

Mozilla Firefox Browser – Using the HTTP/2 Indicator Add-on

  1. Install Add-on First, you will need to load the HTTP/2 Indicator add-on.
     

  2. Once it’s loaded, you can go to the page that you want check for using HTTP/2.
  3. check for lighting bolt icon to confirm HTTP/2 usage If the page is using HTTP2, you will see a lightning bolt graphic in the address bar. You can also hover over it for confirmation in text.
     

Verify HTTP/2 using CLI

Linux terminal users can use the following command to check if their website is using HTTP/2:

curl --http2 domain.com -I

The response should start with HTTP/2 200.

Using localhost instead of the domain or server hostname while logged into SSH may not work.

KeyCDN HTTP/2 Test Tool

One of the fastest and easiest ways to tell if your site has HTTP/2 enabled is to use the KeyCDN HTTP/2 Test Tool. All you need to do is submit your website URL into form to verify your status.

KeyCDN HTTP/2 test result

Optimize for HTTP/2

The main issue here is modifying your site to remove optimization techniques that you may have previously used. If you use the following with your website, then you may need to make some changes in order to make sure that you’re taking advantage of using HTTP/2:

  • Inline CSS and JS – Since there is no overhead for the request for these files, it no longer needs to be inline with the rest of the page code.
  • Image Spriting – Combining several images into a larger image was know as “spriting.” The implementation of HTTP/2 eliminates the need to do this.
  • Concatenating CSS and JS files – This was another technique used to reduce the number requests that can be removed with the implementation of HTTP/2.
  • Domain Sharding – This is the practice of using multiple CDN domains to serve static website files. HTTP/2 removes the need for parallel connections (to the multiple CDN domains) using a single connection for parallel downloads.

Stay Ahead with HTTP/3

If you want to stay ahead on website performance, look out for the HTTP/3 protocol, which is supported by Firefox, Chrome, Edge, and Safari. However, Safari is the only web browser with HTTP/3 support enabled by default. Meanwhile, native NGINX HTTP/3 support is expected to come in the 1.19 release.

Looking for other ways to improve website performance? Learn more about how to secure your Linux cloud server.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!