HTTP2 is a new and improved web technology that allows browsers to make multiple simultaneous calls to a web server. This means web servers that support HTTP2 can accept multiple requests from a same client in parallel. In contrast to HTTP1 this results in much faster page loads and better responsiveness of the website.
This guide will show you how to enable http2 on your webserver. This particular one is for Apache2 Web Server.
- Enable HTTP2 on NGINX.
- Enable HTTP2 on IIS
How To Enable HTTP2 on Apache2 Web Server
Install Apache2 Web Server
sudo apt-get update sudo apt-get install apache2 -y
Open the apache configuration file:
Update apache2 configuration.
Debian: sudo nano /etc/apache2/httpd.conf
sudo nano /etc/apache2/apache2.conf
If you’re running a docker container with httpd:latest image, you’ll find the configuration file for apache2 at /usr/local/apache2/conf/httpd.conf
- Remove the # on the line containing LoadModule http2_module modules/mod_http2.so
- Remove the # on the line containing LoadModule mpm_event
- Add the # at the beginning of the line containing LoadModule php7.2 (or whichever version of php is there)
- Add the # at the beginning of the line containing LoadModule mpm_prefork
For ubuntu you can run:
sudo a2enmod http2 sudo a2dismod php7.2 (or whichever version of php you have) sudo a2dismod mpm_prefork sudo a2enmod mpm_event
Then, add this at the end of the configuration file:
Protocols h2 h2c http/1.1
now save and exit.
Restart the apache2 web server daemon
sudo service apache2 restart
How to test if http2 is working.
Goto your website and open inspect mode from the browser And check one of the requests to your web server. You should see the header Upgrade: h2,h2c on the response header.
If you’re running php, you will need to configure php-fpm and fcgi proxy on apache2, my next guide will show you how to configure php-fpm when using mpm_event and http2.
Looking for a simpler way to achieve this? Our webservers have http2 and php-fpm enabled by default. Get started with our affordable hosting plans.