How to Enable HTTP/2 Support in Apache

r00t October 25, 2017

Enable HTTP/2 Support in Apache

In this tutorial we’ll learn how to enable HTTP/2 support in Apache. We will also install and configure its prerequisites. I’ve been a keen follower of these exciting changes to the HTTP specification over the past couple of years — with the launch of the HTTP/2 standard in 2015. If you are unfamiliar with http/2 there are a number of great videos available which outline just what it is and how it is different from http 1.1 — which we’ve been so accustomed to over the years.

In light of these changes and of the ever increasing browser support with this feature (over 70% when employing an SSL/TLS connection), I wanted to give it a try. I had a website on a Digital Ocean droplet, running on Ubuntu 16.04 (LTS) and the LAMP stack already with an SSL certificate setup (the perfect candidate for getting http/2 working). After some digging around on various blogs which were discussing the topic, I came across a few guides that helped, this guide is a combination of a few.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Enable HTTP/2 Support in Apache

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Install or Update Apache.

HTTP/2 protocol supported over Apache version >=2.4.17. So make sure that your Apache version supporting HTTP/2 protocol. If you have not installed Apache or utilizing old version upgrade it first. Use the following commands to include PPA for installing newest Apache2 variation on your Ubuntu system:

apt-get apt-get install software-properties-common python-software-properties
add-apt-repository ppa:ondrej/apache2
apt-get update
apt-get install apache2

Verify Apache version:

apache2 -v

Step 3. Enable HTTP/2 module.

Apache’s HTTP/2 support comes from the mod_http2 module. Enable it from:

sudo a2enmod http2

Add ‘Protocols h2 http/1.1’ to each SSL based virtual hosts. For example, edit the default-ssl configuration file:

nano /etc/apache2/apache2.conf

Add this line at the end:

Protocols h2 http/1.1

Restart Apache for the changes to take effect:

sudo systemctl restart apache2

Step 4. Verify if Website Support HTTP/2.

  • Manually – open IE/Chrome/Firefox and press F12 >> go to network tab and you should see protocol as HTTP/2
  • Online – you can use HTTP/2 Test tool

Congratulation’s! You have successfully enable HTTP/2 support in Apache/2 on your Ubuntu 16.04 server. Thanks for using this tutorial enable HTTP/2 on Ubuntu 16.04 LTS (Xenial Xerus) system.


The Tags:

Leave a Comment

Comments are closed.