Configuring HTTP/2 for WordPress on Ubuntu
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:
a2enmod http2Second step is adding HTTP/2 protocol definition to /etc/apache2/apache2.conf:
Protocols h2 h2c http/1.1
H2Direct on
H2ModernTLSOnly onFollowed by Apache’s restart:
systemctl restart apache2In 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:
apt-get install php7.4-fpmFurthermore, we need some modules enabled and disabled:
a2dismod php7.4
a2dismod mpm_prefork
a2enmod mpm_event
a2enmod proxy_fcgi
a2enconf php7.4-fpmOf course, addition to /etc/apache2/apache2.conf is needed too:
<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:
systemctl restart apache2Congratulations! HTTP/2 should be working now.