Here’s a simple guide showing how you can enable HTTP/2 in Apache on Ubuntu 16.04.
The internet is awesome. It can be used by governments to very efficiently spy on their citizens, it got Donald elected, and it’ll be mentioned in future history books as the main tool used in the second rise of fascism. There are also a few funny cat pictures.
Today’s internet connections are amazingly fast. You younglings might not believe this, but there was a time when we actually had to sit and wait for a website to appear. If you want to experience the internet speeds of the past, give 56k Emulator a try. It will give you the basic idea. And keep in mind that 56K modems were freakin’ fast when they became available.
But I digress. Sorta. Even though today’s internet connections are fast, the technology used to push propaganda around inside the tubes is old and slow. HTTP/1.1 was never intended to be used with the kind of content-heavy website we have today. Thankfully, there’s a new option available, the marvelous RFC-7540. Or HTTP/2, if you will.
HTTP/2 is a major revision of HTTP/1.1. Its main goal is to make web sites appear in your browser quicker, and with the need to send less data than with HTTP/1.1. The “number one HTTP server on the internet”, Apache 2 only has experimental support for HTTP/2. This means that it’s not available in the version Ubuntu 16.04 includes by default.
Once again, we have to turn to our PPA packaging hero Ondřej Surý for support. Not only does he maintain packages for the latest and greatest version of PHP (that we used here), he also makes sure Ubuntu users can be on the bleeding edge of Apache goodness.
Getting on the HTTP/2 Highway
These instructions assume that you’ve already got Apache2 installed, and that the sites you want to enable HTTP/2 for has TLS (HTTPS) enabled. If you don’t, and have no idea how to do this, please consult the internet. Log in to your Ubuntu box (if you’re doing it over SSH, your account is of course secured with 2FA). Then, run the following commands:
# Install add-apt-repository. sudo apt-get install software-properties-common # Add Surý's Apache2 PPA repository. sudo add-apt-repository ppa:ondrej/apache2 # Update your local package list. sudo apt-get update # Upgrade Apache2 with the new packages from Surý. sudo apt-get upgrade
When running the “upgrade” command, APT might tell you that a lot of the Apache2 packages are being kept back. If that’s the case, run the following commands:
# Force install of held back Apache2 packages sudo apt-get install COPY-LIST-OF-KEPT-BACK-APACHE2-PACKAGES-HERE
Next, enable HTTP/2.
sudo a2enmod http2
Then, add the Protocols directive to the VirtualHost configuration of the sites you want to server over HTTP/2:
<VirtualHost *:443> ServerName your-awesome-site.com Protocols h2 http/1.1 </VirtualHost>
Finally, restart Apache2.
# Restart Apache2. sudo service apache2 restart
All done. Your site is now being server using HTTP/2. Hooray!