Skip to main content

Enable HTTP/2 support in Apache2 (with PHP)

Category: Linux

Starting from Apache 2.4.27, the Apache MPM (Multi-Processing Module) prefork no longer supports HTTP/2. Enabling HTTP/2 support requires some more steps than just enabling the apache module.

First you should deacticate the profeork module and activate mpm_event instead.

sudo a2dismod mpm_prefork
sudo a2enmod mpm_event

mpm_event is ment to work with php-fpm, that is supporting threads unlike the php apache module.

#deactivate apache php & fcgi module 
sudo a2dismod php7.2
sudo a2enmod proxy_fcgi setenvif

#install php-fpm (PHP 7.2)
sudo apt-get install php7.2-fpm

#activate apache php-fpm configuration
sudo a2enconf php7.2-fpm

Now we can activate the http2 module and setup our vhosts.

sudo a2enmod http2
#vhost configuration
<VirtualHost *:443>
  Protocols h2 http/1.1

Finally we do need to restart the php-fpm process and the apache2 server that our changes can take effect.

sudo systemctl restart php7.2-fpm.service
sudo systemctl restart apache2