How to enable HTTP2 on Ubuntu 16.04 server with Apache 2.4.272 min read

In

,

Two days ago I wanted to enable HTTP2 my website because it’s faster, simpler, and more robust than HTTP1.  Check this link to read more about it.
I have searched online how to enable it and I have followed almost every tutorial to enable it, but I couldn’t get it working. Everything seemed to be okay and working, but HTTP2 wasn’t enabled.
Head in Hands- Peshmerge.io

On Stackoverflow, on serverfault or other personal blogs where people explained to do that, but still no luck. But I was like ” I won’t give it up, I will just still try to get it up and running”.

I could finally enable it by disabling and enabling two modules from Apache. The first module was mpm_prefork which must be disabled because it doesn’t support HTTP2. The second module was mpm_event  which must be enabled. Not you can’t enable them both of them together.

To enable HTTP2 for Apache 2 on Ubunut 16.04 server you have to do the following:

Edit the main config file of Apach2 on your server
sudo vim /etc/apache2/apache2.conf  and add the following line to the end of the file

Protocols h2 h2c http/1.1

instead of adding the line to each <VirtualHost> file.

Disable mpm_prefork by running: sudo a2dismod mpm_prefork
Enable mpm_event by running: sudo a2enmod mpm_event
Enable HTTP2 module by running: sudo a2enmod http2
Restart Apache by running: sudo service apache2 restart

Check if it’s enabled by using this tool https://http2.pro/ or you can check your browsers by using developer tools. Open your website and open developer tools in Google Chrome and go to Network tab. If everything is okay you have to see h2 by every call. Like this:

HTTP2_screenshot_Chrome_DeveloperTools
Checking HTTP2 in Chrome Developer Tools

You can see in the column “Protocol” that h2 is presented 🙂

Please don’t hesitate to leave a comment  if you have further questions or suggestions.

Related resources

  • https://httpd.apache.org/docs/2.4/howto/http2.html
  • https://techwombat.com/enable-http2-apache-ubuntu-16-04
  • https://http2.pro/doc/Apache

Leave a Reply

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.