Enable http/2

Dec 19, 2019 | 3 minutes read

Authors: Luke Rawlins

Tags: apache, fedora, http/2

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 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 mpm_prefork 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 mpm_event module, we will walk through how to make that change momentarily.

Uncomment the line:

    LoadModule mpm_event_module modules/

Make sure to place a # in front of the line:

    #LoadModule mpm_prefork_module modules/

You only want to have one mpm module loaded so make sure that mod_mpm_event is the only active module. Prefork and worker should be commented out.

Next edit /etc/httpd/conf.d/php.conf : - Look for the SetHandler parameter in the local php-fpm 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://"

Ensure that the following parameter is active. Copy and paste it in under “<FilesMatch .(php|phar)$>” if it isn’t present.

    SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"

Ensure that SetHandler proxy:fcgi:// 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!