Authors: Luke Rawlins
The http 2.0 protocol is designed for increased speed and performance. The protocol was published for release in 2015 and is supported by Apache 2.4 using the mod_http2 module.
Note: You will need to have a valid ssl cert for all practical purposes to implement http/2. Many web browsers including Firefox will not use http/2 on a site without an ssl cert. You can obtain a free ssl cert with letsencrpyt, check out https://certbot.eff.org for more info.
This write up is based on Fedora 30 and Apache 2.4, but it should also work on CentOS 8 or RHEL 8.
sudo dnf install php-fpm mod_fcgid fcgi mod_http2
In order to enabled http/2 in Apache you need to make sure that you are not using the
module. The prefork module is non-threaded and cannot handle the multiplexed connection that http/2 requires. For the best results you will want to switch to the
module, we will walk through how to make that change momentarily.
Uncomment the line:
LoadModule mpm_event_module modules/mod_mpm_event.so
Make sure to place a # in front of the line:
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
You only want to have one mpm module loaded so make sure that
is the only active module. Prefork and worker should be commented out.
: - Look for the
parameter in the
section shown below.
# # Redirect to local php-fpm (no mod_php in default configuration) # <IfModule !mod_php5.c> <IfModule !mod_php7.c> # Enable http authorization headers SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 <FilesMatch \.(php|phar)$> SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost" #SetHandler "proxy:fcgi://127.0.0.1:9000" </FilesMatch> </IfModule> </IfModule>
Ensure that the following parameter is active. Copy and paste it in under “<FilesMatch .(php|phar)$>” if it isn’t present.
in that section is commented out with a
Near the top of your virtual hosts file, under the “ServerName” parameter add the following:
Protocols h2 h2c http/1.1
sudo systemctl enable php-fpm && sudo systemctl start php-fpm
Restart the httpd service:
sudo systemctl restart httpd
Visit your website and click a few links, refresh the page a couple times, and then take a look at your web logs.
sudo grep "HTTP/2.0" /var/log/httpd/site_access.log
If all the above steps were completed successfully you should get some log entries returned that contain “HTTP/2.0”. If so congratulations your site is now supporting http/2!
If you’d like to get in touch, contact with me via email.