However, there are some prerequisites to enabling HTTP/2 for your website. In this article, I will show how to get HTTP/2 working on your site running on Apache webserver.
First, enable HTTPS for your site. Configure HTTPS for your website, if you do not already have the SSL certificate or use Let’s Encrypt which is an open-source SSL certificate.
Older versions of Apache do not support HTTP/2. You need to have Apache 2.4.24 and above. If you are using Ubuntu 16.04 LTS, then upgrade to Ubuntu 18.04 LTS.
By default, PHP runs on Apache via mod_php. According to Apache documentation, HTTP/2 is not compatible with Apache’s prefork multi-processing module. Moreover, prefork is not most people favourite now. A switch to a modern module is better.
Therefore, switch to php7.x-fpm from mod_php. Run the following commands to effect the necessary changes.
sudo apt-get install php7.2-fm sudo a2enmod proxy_fcgi sudo e2enconf php7.2-fpm sudo a2dismod php7.2 sudo a2dismod mpm_prefork sudo a2enmod mpm_event sudo service apache2 restart
Now, let’s enable mod_http2 module. Use the command below to enable mod_http2:
sudo a2enmod http2 sudo service apache2 restart
Finally, enable HTTP/2 protocol by updating /etc/apache2/apache2.conf with the code below:
Protocols h2 http/1.1