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:

Terminal
a2enmod http2

Second step is adding HTTP/2 protocol definition to /etc/apache2/apache2.conf:

/etc/apache2/apache2.conf
Protocols h2 h2c http/1.1
H2Direct on
H2ModernTLSOnly on

Followed by Apache's restart:

Terminal
systemctl 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:

Terminal
apt-get install php7.4-fpm

Furthermore, we need some modules enabled and disabled:

Terminal
a2dismod 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:

Terminal
systemctl restart apache2

Congratulations! HTTP/2 should be working now.

One thought to “Configuring HTTP/2 for WordPress on Ubuntu”

  1. 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.

Leave a Reply to Hiroshi Takahashi Cancel reply

Your email address will not be published. Required fields are marked *