How to Enable HTTP/2 in Apache

Disable the mod_php module

Before we can switch the Apache MPM module in the next step to mpm_event, we will have to disable the old mod_php mode and replace it with the more modern PHP-FPM mode. The commands differ for each Operating system version, please use the ones that match your installed system.

sudo apt-get install php7.0-fpm
sudo a2dismod php7.0
sudo a2enconf php7.0-fpm
sudo a2enmod proxy_fcgi

Enable an Apache MPM that is compatible with HTTP/2

By default, Apache will use the prefork MPM. This MPM is not compatible with HTTP/2, so we will have to replace it with the more modern mpm_event module.

First, we disable mpm_prefork module:

sudo a2dismod mpm_prefork

Then we enable the mpm_event module:

sudo a2enmod mpm_event

Enable HTTP/2 support in Apache

To get HTTP/2 working on Apache you need to enable and load SSL and HTTP/2 modules. To do so, you may run the following in your terminal:

sudo a2enmod ssl

and then

sudo a2enmod http2

To activate these new modules, you need to run:

sudo systemctl restart apache2

After enabling and loading necessary Apache modules, navigate to your Apache configuration directory and edit Apache configuration.

To enable HTTP/2 on your Apache web server add one of the following to your global Apache configuration or inside of a particular virtual host.

Protocols h2 http/1.1

Here is the minimal virtual server configuration that can be used to enable HTTP/2 in some virtual host:

<VirtualHost *:443>
  ServerName example.com
  ServerAlias www.example.com
  DocumentRoot /var/www/public_html/example.com
  SSLEngine on
  SSLCertificateKeyFile /path/to/private.pem
  SSLCertificateFile /path/to/cert.pem
  SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
  Protocols h2 http/1.1
</VirtualHost>