How to Install HTTP/2 In Apache Ubuntu Environment For Multiplexing and Server Push

Submitted by techyboy on Sun, 11/05/2017 - 12:02
http2 implementation in apache ubuntu

HTTP/2 is the advanced version of HTTP/1.1 protocol used widely at present. HTTP/1.1 is supported by almost all browsers. You can easily feel performance improvements of blog type sites when run under the support of HTTP/2 protocol. Browsers request less number of connections to servers decreasing Round Trip Time considerably, which leads to page speed boosts. HTTP/2 actually evolved from Google SPDY ( SPeeDY ) protocol which aimed at reducing transport layer delays in exchanging data between client and server. All servers are by default shipped with HTTP/1.1 support. You as a website caretaker / developer needs to enable the HTTP/2 support to exploit the benefits of Multiplexing and Server Push.

Problems With HTTP/1.1

  • Numerous Requests: Browsers using HTTP/1.1 make a number of requests ( even unnecessary ) to the server in the process of rendering a web page. Maximum number of simultaneous request from a single domain is only 6. Each request causes extra burden on the server in connection negotiation itself. To load a single webpage, browser / client should make tens / hundreds of requests depending on the webpage content. More number of images, JS files, CSS files and other files contribute to so many http requests.
  • Mandatory SSL Certificates: All browsers mandate implementation of TLS ( Transport Layer Security ) feature in order to support HTTP/2 protocol. Buying and Installing SSL Certificates require Money and Web Developers to install. You can of course use self signed certificates for time being.
  • Wait Time & Resource Block: As HTTP/1.1 proceeds making requests and responses a number of times dependent on number of resources, Wait time is introduced by subsequent resources waiting for their turn.

 

Advantages of HTTP/2

  • Less TCP Connections: HTTP/2 makes a single TCP connection a fetch a number of resources in one go unlike making a large number of requests by HTTP/1.1.  HTTP/2 requests and responses are in a binary format thus enabling Multiplexing of parallel streams. Almost 74% of HTTP/1.1 transactions are for fetching a single resource in today's world.
  • Server Push: HTTP/2 enables the server to send additional resources to the client even when not asked to avoid subsequent requests by the client. These Push resources can be Cached, Prioritised and Multiplexed along with other resources.
  • Header Compression: Header compression using HPACK algorithm reduces combined header size. Also the client and server maintain an indexed list of already accessed header fields. This also reduces header overhead. The reduced size will be less than 80% of the actual value. This helps low bandwidth connections to render the page fast.

Google withdrew its support for SPDY in early 2016 seeing its implementation in HTTP/2.

 

Steps to Implement HTTP/2 in Apache Ubuntu

1. Add ONDREJ/APCHCHE2 repository

console> sudo add-apt-repository ppa:ondrej/apache2

 

2. Update your existing Apache2 to get updated version

console> sudo apt-get upgrade apache2

 

3. If second step fails, you can do update and install http2.

console> sudo apt-get update
console> sudo apt-get install apache2 -y

 

4. Now enable HTTP2 module

console> sudo a2enmod http2

console> apachectl restart

 

5. If you are using regular PHP7.1 with MPM_PREFORK, you may not enable your server with http2 support. So disable PHP7.1 to enable PHP7.1-FPM module.

console> apachectl stop

console> sudo a2dismod php7.1

console> sudo a2dismod mpm_prefork

console> sudo apt-get install php7.1-fpm

console> sudo a2enconf php7.1-fpm

console> sudo a2enmod mpm_event

console> apachectl start

 

6. Now find your VHOST.CONF file and add a line to accept HTTP/2 protocol.

Before:

<VirtualHost _default_:443>
        
        ServerAdmin webmaster@localhost
        ServerName abcd.com
        ServerAlias www.abcd.com

..

...

</VirtualHost>

 

After:

<VirtualHost _default_:443>
    
        Protocols h2 http/1.1
        
        ServerAdmin webmaster@localhost
        ServerName abcd.com
        ServerAlias www.abcd.com

..

...

</VirtualHost>

 

7. After restarting server, check for correct implementation of HTTP/2 at KeyCDN site.

 

http2 test at keycdn

 

 

 

Add new comment

Next Article