The right way to Allow HTTP/2 in Apache on Ubuntu

Because the inception of the World Large Net (www), the HTTP protocol has advanced through the years to ship safe and quick digital content material over the web.

Essentially the most extensively used model is HTTP 1.1 and whereas it packs with function enhancements and efficiency optimizations to handle the shortcomings of earlier variations, it falls quick of some different salient options which were addressed by the HTTP/2.

What are the Limitations of HTTP/1.1?

The HTTP/1.1 protocol is fraught with the next shortcomings that make it much less best particularly when working high-traffic net servers:

  1. Delays in loading net pages on account of lengthy HTTP headers.
  2. HTTP/1.1 is just capable of ship one request for every file per TCP connection.
  3. On condition that HTTP/1.1 processes one request for each TCP connection, browsers are pressured to ship a deluge of parallel TCP connections to concurrently course of the requests. This results in TCP congestion and in the end bandwidth wastage and community degradation.

The above-mentioned issues usually led to efficiency degradation and excessive overhead prices in bandwidth utilization. HTTP/2 got here into the image to handle these issues and is now the longer term for HTTP protocols.

Benefits of Utilizing HTTP/2

It provides the next benefits:

  1. Header compression that minimizes shopper requests and thereby lowers bandwidth consumption. The resultant impact is quick web page load speeds.
  2. Multiplexing a number of requests over one TCP connection. Each the server and the shopper can break down an HTTP request into a number of frames and regroup them on the different finish.
  3. Sooner net performances which consequently result in higher web optimization rating.
  4. Improved safety since most mainstream browsers masses HTTP/2 over HTTPS.
  5. HTTP/2 is taken into account extra mobile-friendly due to the header compression function.

That mentioned, we’re going to allow HTTP/2 on Apache on Ubuntu 20.04 LTS and Ubuntu 18.04 LTS.


Earlier than getting began, be certain that you allow HTTPS on the Apache webserver earlier than enabling HTTP/2. It’s because all mainstream net browsers assist HTTP/2 over HTTPS. I’ve a site title pointed to an occasion on Ubuntu 20.04 which is working Apache server secured utilizing Let’s Encrypt certificates.

Additionally, it’s beneficial you might have Apache 2.4.26 and later variations for manufacturing servers desiring to make a shift to HTTP/2.

To examine the model of Apache you might be working, execute the command:

$ apache2 -v

Check Apache Version in Ubuntu

Examine Apache Model in Ubuntu

From the output, you’ll be able to see that we’re utilizing the newest model, which is Apache 2.4.41 on the time of penning down this text.

Allow HTTP/2 on a Apache Digital Host

To get began, first affirm that the webserver is working HTTP/1.1. You are able to do this on a browser by opening the developer instruments part on Google chrome utilizing the Ctrl +SHIFT + I mixture. Click on on the ‘Community’ tab and find the ‘Protocol’ column.

Confirm HTTP Protocol Version

Affirm HTTP Protocol Model

Subsequent, allow the HTTP/2 module on Ubuntu by working the next command.

$ sudo a2enmod http2

Enable HTTP/2 on Ubuntu

Allow HTTP/2 on Ubuntu

Subsequent, find and edit your SSL digital host file, when you’ve enabled HTTPS utilizing Let’s Encrypt, a brand new file is created with a le-ssl.conf suffix.

$ sudo vim /and many others/apache2/sites-enabled/your-domain-name-le-ssl.conf

Insert the directive beneath after the <VirtualHost *:443> tag.

Protocols h2 http/1.1

Enable HTTP/2 on Apache

Allow HTTP/2 on Apache

To avoid wasting the adjustments, restart Apache webserver.

$ sudo systemctl restart apache2

To examine if HTTP/2 is enabled, fetch the HTTP headers utilizing the next curl command as present.

$ curl -I –http2 -s | grep HTTP

Check HTTP/2 Support in Apache

Examine HTTP/2 Help in Apache

It is best to get the output proven.

HTTP/2 200

On the browser, reload your website. Then head again to the developer instruments and ensure HTTP/2 denoted by the h2 label on the ‘Protocol’ column.

Confirm HTTP/2 Protocol Version

Affirm HTTP/2 Protocol Model

When Utilizing mod_php Module with Apache

In case you are working Apache alongside the mod_php module, it’s essential to change to PHP-FPM. It’s because the mod_php module makes use of the prefork MPM module which isn’t supported by HTTP/2. You must uninstall the prefork MPM and change to the mpm_event module which can be supported by HTTP/2.

In case you are utilizing the PHP 7.Four mod_php module, for instance, disable it as proven:

$ sudo a2dismod php7.4

Disable mod_php Module

Disable mod_php Module

Thereafter, disable the prefork MPM module.

$ sudo a2dismod mpm_prefork

Disable Prefork MPM in Apache

Disable Prefork MPM in Apache

After disabling the modules, subsequent, allow the Occasion MPM, Fast_CGI, and setenvif modules as proven.

$ sudo a2enmod mpm_event proxy_fcgi setenvif

Enable Event MPM in Apache

Allow Occasion MPM in Apache

Set up PHP-FPM on Ubuntu

Subsequent, set up and begin PHP-FPM as proven.

$ sudo apt set up php7.4-fpm
$ sudo systemctl begin php7.4-fpm

Then allow PHP-FPM to begin at boot time.

$ sudo systemctl allow php7.4-fpm

Subsequent, allow PHP-FPM as Apache’s PHP handler and restart the Apache webserver for the adjustments to be effected.

$ sudo a2enconf php7.4-fpm

Allow HTTP/2 Help in Apache Ubuntu

Then allow the HTTP/2 module as earlier than.

$ sudo a2enmod http2

Restart Apache to synchronize all of the adjustments.

$ sudo systemctl restart apache2

Lastly, you’ll be able to take a look at in case your server is utilizing the HTTP/2 protocol utilizing the curl command as proven.

$ curl -I –http2 -s | grep HTTP

Check HTTP/2 Protocol in Apache

Examine HTTP/2 Protocol in Apache

It’s also possible to choose to make use of the developer instruments on the Google Chrome browser to confirm as earlier documented. We now have to the top of this information, We hope you discovered the knowledge helpful and that you may comfortably allow HTTP/2 on Apache with ease.


Germany Devoted Server

Leave a Reply