Last year I wrote this exact article only to find out it's no longer current. So, as I rebuilt my web server on a new VM, I decided to bring it a bit of update for PHP 7.4
The first step, of course, is enabling HTTP/2 module:
Terminala2enmod http2
Second step is adding HTTP/2 protocol definition to /etc/apache2/apache2.conf
:
/etc/apache2/apache2.confProtocols h2 h2c http/1.1
H2Direct on
H2ModernTLSOnly on
Followed by Apache's restart:
Terminalsystemctl restart apache2
In ideal world this would be it. But, despite Apache starting without error, a check via Developer Tools will show HTTP 1.1 is still in use. So we need an additional PHP with FastCGI support:
Terminalapt-get install php7.4-fpm
Furthermore, we need some modules enabled and disabled:
Terminala2dismod php7.4
a2dismod mpm_prefork
a2enmod mpm_event
a2enmod proxy_fcgi
a2enconf php7.4-fpm
Of course, addition to /etc/apache2/apache2.conf
is needed too:
/etc/apache2/apache2.conf<Files "*.php">
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
</Files>
If you configured prefork
before, you also need to remove it's configuration. In my case StartServers
, MinSpareServers
, MaxSpareServers
, MaxClients
, and MaxRequestsPerChild
settings had to go.
Of course, another Apache restart is upon us:
Terminalsystemctl restart apache2
Congratulations! HTTP/2 should be working now.
Thank you for the wonderful information. Until now, I tried various things and it didn’t go well, but with your information, HTTP2 started to work. I appreciate it very much.