apache http2

We’ll show you, How To Set Up Apache with HTTP/2. HTTP/2 is the first major HTTP protocol update since 1997. The main goal of HTTP/2 is to decrease latency, reduce total number of TCP connections, thus improve page load speed in web browsers. HTTP/2 is backwards-compatible with HTTP/1.1, all application semantics of HTTP are the same, except the way of transmitting data via TCP connection. HTTP/2 leverages multiplexing and allows asynchronous (parallel) requests and provides data compression of HTTP headers. Also, the server push method in HTTP/2 allows server to send multiple responses for a single request.

HTTP/2 support is not included in Ubuntu 16.04, neither with nginx nor with Apache because this feature is considered as experimental by the Apache httpd upstream project, so it is not possible to enable it on an Ubuntu 14.04 VPS using the a2enmod command:

a2enmod http2
ERROR: Module http2 does not exist!

HTTP/2 support should be enabled in Ubuntu 16.04 after the Apache httpd upstream considers this support to be non-experimental.
Luckily, the Http2 module is included in the source, so follow these steps to enable HTTP/2 support on Apache web server:

1. Add source URIs

Add source URIs to the sources.list file if it is not already done so:

vi /etc/apt/sources.list

add the following lines at the end:

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

2. Download the package lists from the repositories

Run ‘apt-get update’ command to download the package lists from the repositories and update them to get information on the newest versions of packages, then update the Ubuntu 16.04 OS packages using the ‘apt-get upgrade’ command:

apt-get update
apt-get upgrade

3. Install pre-requisites

Install the required pre-requisites:

apt-get install curl devscripts build-essential fakeroot

4. Create new user

Create a new user, or switch to an existing user account:

sudo adduser <username> sudo
su <username>

Replace <username> with an actual username.

5. Install libnghttp2-dev

Install the libnghttp2-dev package:

[user]$ cd ~
[user]$ sudo apt-get install libnghttp2-dev
[user]$ mkdir apache2
[user]$ cd apache2

6. Download the apache2 sources

Download the apache2 sources on your server and build them:

[user]$ apt-get source apache2
[user]$ sudo apt-get build-dep apache2
[user]$ cd apache-2.4.18
[user]$ sudo apt-get install curl devscripts build-essential fakeroot
[user]$ fakeroot debian/rules binary
[user]$ sudo cp debian/apache2-bin/usr/lib/apache2/modules/mod_http2.so /usr/lib/apache2/modules/
[user]$ exit

7. Load the HTTP/2 module.

Load the HTTP/2 module. Create a file /etc/apache2/mods-available/http2.load and add the following lines:

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

<IfModule http2_module>
LogLevel http2:info

8. Enable and configure Apache HTTP2 module

Enable the http2 module:

a2enmod http2

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

vi /etc/apache2/sites-enabled/default-ssl.conf
<IfModule mod_ssl.c>
 <VirtualHost _default_:443>
 ServerAdmin [email protected]
 ServerName your-domain.com
 Protocols h2 http/1.1
 DocumentRoot /var/www/html
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
 SSLEngine on

 SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
 SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

 <FilesMatch "\.(cgi|shtml|phtml|php)$">
 SSLOptions +StdEnvVars
 <Directory /usr/lib/cgi-bin>
 SSLOptions +StdEnvVars


Or, add ‘Protocols h2 http/1.1’ to main Apache configuration to enable http2 on all websites:

vi /etc/apache2/apache2.conf

Add this line at the end:

Protocols h2 http/1.1

9. Restart Apache web server

Restart Apache for the changes to take effect:

service apache2 restart

That is it. The HTTP/2 support has been enabled on your Apache web server.

Apache HTTP/2Of course you don’t have to set up Apache with HTTP/2 on Ubuntu 16.04, if you use one of our High-Performance VPS Hosting services, in which case you can simply ask our expert Linux admins to set up Apache with HTTP/2 support for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on how to set up Apache with HTTP/2 Support on Ubuntu 16.04,  please share it with your friends on the social networks using the buttons below, or simply leave a reply below. Thanks.