How to Enable HTTP/2 in Apache


enable http/2 in apache

HTTP/2 is a powerful protocol that improves website performance by reducing the number of requests sent to your web server. It supports many new technologies like Header compression, Push notifications, parallel load of page elements over single TCP/IP connection and more. Here’s how to enable HTTP/2 in Apache.

 

 

How to Enable HTTP/2 in Apache

Here are the steps to enable HTTP/2 in Apache. Please note, that HTTP/2 is available only since Apache 2.4.17.

So if you have Apache 2.2 or lower version, you will need to upgrade Apache to a compatible version.

 

1. Download Apache

Download the latest version of Apache from its website.

 

2. Extract the Archive

Extract the downloaded file into a folder


sudo gunzip -c httpd-2.4.25.tar.gz | tar xvf -

 

3. Compile with mod_http2, mod_ssl

You will see a new folder created. Go inside the folder. Build Apache with configure command


sudo ./configure --enable-ssl --enable-so --enable-http2

 

Make sure there is no error message from the above command. After that, build Apache web server


sudo make
sudo make install

 

This will ensure that Apache is installed with http2 module

 

4. Configure Apache server

Take a backup of your Apache config file. You will generally find it at one of the following locations, depending on your Linux distribution and type of installation:

 

Open Apache config file in a text editor


$ sudo vim /etc/httpd/conf/httpd.conf

 

Look for the following line. If not present, add it.


LoadModule http2_module modules/mod_http2.so

If you find a ‘#’ sign at its beginning, remove it.

 

Next, add the Protocols directive as shown below


Protocols h2 h2c http/1.1

In the above command,

  • h2 – instructs Apache to support HTTP/2 protocol over SSL/TLS
  • h2c – instructs Apache to support HTTP/2 over TCP
  • http/1.1 – serve the request over HTTP/1.1 if client doesn’t accept HTTP/2

 

If you have setup virtual hosts, then you need to add the Protocols directive in the appropriate virtual hosts file.

 

3. Restart Apache web server

Restart Apache web server to apply changes


$ sudo /etc/init.d/apache2 start [Debian or Ubuntu]
# sudo apachectl restart [RHEL, CentOS or Fedora]

 

 

 

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!