How to switch to HTTP/2 from HTTP/1.1 in Apache on Ubuntu 18.04

Requirements

  1. HTTPS – HTTP/2 only works with HTTPS. If you have not switched your site to HTTPS, you can switch to https using let’s encrypt free SSL certificate. Follow this article to switch to SSL.
  2. Apache Version – The required minimum version of Apache to support HTTP/2 is 2.4.24. If you are on the LTS branch of Ubuntu 16.04 or 14.04, this means you need to upgrade to Ubuntu 18.04 or Update to latest version of Apache.
  3. PHP FPM – HTTP/2 is not compatible with Apache’s prefork multi-processing module, so if you run PHP in Apache via mod_php, you need to switch to FPM. FPM is newer and faster prefork basically seems to be obsolete, so it does not hurt to switch to something better like event MPM.

Step 1 – Switch from Apache’s PHP Module of MPM Prefork to Event FPM

Run the following commands:

sudo apt-get install php7.2-fpm
sudo a2enmod proxy_fcgi
sudo a2enconf php7.2-fpm
sudo a2dismod php7.2
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo service apache2 restart

Step 2 – Installing and Enabling HTTP/2 in Apache

Enable the module mod_http2:

sudo a2enmod http2
sudo service apache2 restart

Enable the HTTP/2 protocol by adding the following to /etc/apache2/sites-enabled/example-vhost.conf:

sudo nano /etc/apache2/sites-enabled/example-vhost.conf

Add the below lines in virtual host file.

SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
Protocols h2 http/1.1
SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-A$

Restart Apache Server

sudo service apache2 restart

Step 3 – How to Verify that HTTP/2 is Working.

Cloudflare put together a comprehensive list of ways you can check a website for HTTP/2 support. The easiest to use are probably Chrome Dev Tools (network view, add the Protocol column) or the online test from KeyCDN.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.