Apache: Enabling HTTP/2

This tutorial shows how to enable HTTP/2.0 with Apache.

873 views
d

By. Jacob

Edited: 2019-11-21 06:00

Enabling HTTP/2.0 with the Apache HTTP Server is a very straight forward process. You simply need to enable the http2 module from a command line.

HTTP/2 is the next generation of the HTTP protocol, and it is very useful when you are looking to make use of new features, as well as speed up loading of your pages. The latter is especially true if your page includes a lot of external resources.

1. To install HTTP/2 on your server, all you have to do is run the following command in a terminal:

sudo a2enmod http2

2. Then add the following in: /etc/apache2/apache2.conf:

Protocols h2 http/1.1

3. Finally you may restart the server:

sudo service apache2 restart

See also: Starting, Stopping and Restarting Web-servers in Linux

Checking if HTTP/2.0 is working

If you are working with PHP, you can easily tell what protocol a request was made with via SERVER_PROTOCOL, in the global $_SERVER variable. For example:

echo $_SERVER["SERVER_PROTOCOL"];

The output should be "HTTP/2.0".

Tell us what you think:

  1. Understanding file permissions in Unix / Linux based systems, and how to make files immutable.
  2. In this article I will explain how to enable a swapfile on small instances, and why it might be useful, even if you do have enough physical memory.
  3. How to determine an optimal value for pm.max_children and related php-fpm settings for your server and web applications.
  4. Tutorial showing how to configure a VirtualBox Guest VM with HOST-only and NAT adapter, while using the WWW folder from the HOST OS.
  5. You may have wondered what the /etc/php/8.0/conf.d/ directory is for in Debian and Ubuntu, and whether it is better to edit the conf.d files than editing php.ini directly; find out in this Tutorial.

More in: Linux servers