HTTP/2 with WordPress and Apache
My web site contains great content however is not fully optimized for speed. From time to time, I have to deal with problems caused by the cache plugin. Therefore, caching is sometimes even deactivated. Serving content slow is still better than not serving content at all. Another performance hit is caused by my site not using HTTP/2 (or rather: wasn’t). In Chrome developer tools, the protocol served by the web server can be seen HTTP/1.1 is used.
Serving a web site via HTTP/1.1 isn’t as bad as it sounds. The web site will be delivered without problems. But Google is the problem here. They are using the protocol to decide if your page gets a higher ranking or not. Their tools even recommend using HTTP/2. For instance, using Google PageSpeed Insights for my site gives the following result.
Using HTTP/2 is given as one of the recommendations.
To be able to serve a web site with HTTP/2 and Apache, version 2.4.17 is needed. The module used is named mod_http2. To find out if the currently installed Apache matches that version requirement, run:
As long as the version reported is at least 2.4.17, http/2 is supported.
Base configuration for Apache 2 to activate HTTP/2 is to load the module and adjust the configuration to activate http/2. After Apache is ready the correct PHP engine must be activated. Then WordPress will be accessed via http/2.
The module library is available in the directory modules.
To be able to use the http2 module, load and activate it in the Apache configuration. In my case, the config file is: 00-base.conf. Add or uncomment the line:
LoadModule http2_module modules/mod_http2.so
Maybe the module is already added to the list.
After loading the http2 module, activate the protocol inside Apache. This is done best in the ssl configuration of Apache. In my case:
Adding the following line activates HTTP2 as a protocol.
Protocols h2 h2c http/1.1
In the virtual host for your SSL site (or your general SSL configuration) you add the instruction to activate HTTP2.
<VirtualHost _default_:443> ServerName www.itsfullofstars.de Protocols h2 h2c http/1.1 ProtocolsHonorOrder Off
Activating HTTP2 module does not mean that your web site is now supporting H2. If H2 is used depends on the Apache prefork module. MPM Prefork is not compatible with H2 and must be replaced by e.g. mpm_event.
yum install php73-fpm
Check that PHP-FPM can start without errors.
If it fails, check the error message. In the above case, the user nginx cannot retrieved. The server is running Apache2 and not NGINX, therefore no nginx user exists in the system.
grep nginx /etc/alternatives/php-fpm.d/*
Change the line to
listen.acl_users = apache
Starting php-fpm must work.
Activate MPM Event
Deactivate the mpm module. Comment out the MPM Prefork module
Now activate MPM Event. With this, the PHP engine is changed.
This concludes the configuration of Apache to run WordPress and serve it via http/2. Open a browser and access the website and look at the protocol reported by the developer tools. If all worked fine, the Apache web server will now serve the website with h2.