Enabling HTTP2 on Apache under Ubuntu 16.04

I reciently upgraded to Ubuntu Server 16.04 and was bummed to find out that HTTP2 support had been removed from Apache. Luckily we can easily add the plug-in and enable it. [1]

To do this, we need to build Apache ourselves and then copy out the one file we need. Let’s make sure we have the prerequisites:

apt-get install devscripts build-essential fakeroot

Now install libnghttp2 and Apache:

apt-get install libnghttp2-dev apache2

Now we build Apache from source. Check to make sure these three lines are added and not commented from /etc/apt/sources.list:

deb-src http://archive.ubuntu.com/ubuntu xenial main restricted universe
deb-src http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe
deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted universe multiverse

And update for good measure:

apt-get update

Now we’re ready to begin:

cd /tmp
mkdir apache2
cd apache2
apt-get source apache2
apt-get build-dep apache2
cd apache-2.4.18
fakeroot debian/rules binary

Now we can move mod_http2.so to Ubuntu’s Apache installation:

cp /tmp/apache2/apache-2.4.18/debian/apache2-bin/usr/lib/apache2/modules/mod_http2.so /usr/lib/apache2/modules/

Next we create the load file:

nano /etc/apache2/mods-available/http2.load

And paste this line:

LoadModule http2_module /usr/lib/apache2/modules/mod_http2.so

Next edit your site’s .conf file to include:

Protocols h2 http/1.1

Now we can enable http2 and restart apache:

a2enmod http2
service apache2 restart

That’s it! For cleanup, you can remove the /tmp/apache2 folder and remove the prerequisites if you no longer need them:

rm -Rf /tmp/apache2
apt-get remove devscripts build-essential fakeroot
apt-get autoremove

References:
1. https://zitseng.com/archives/10470

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s