This article covers:
How to upgrade from http/1.1 to http/2 on a web server.
The Server Environment:
- Sever OS – Ubuntu 18.0.4
- PHP Version – 7.1
- Apache Version – 2.4.33
- Apache MPM (Multi-Processing Module) prefork is used by PHP
If you’re running Apache 2.4, most likely you will have http2 module already installed, all you need to do is enable it:
sudo a2enmod http2
Acordding to the official guide, you also need the libnghttp2 module:
sudo apt-get install libnghttp2-dev
Now configure your virtual host settings to enable http2 protocol:
<VirtualHost *:443> ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/public_html/example.com ... Protocols h2 http/1.1 </VirtualHost>
Then restart Apache 2. To see if HTTP2 is supported on your server you can use this tool.
You can also use this command to see whether http2 is configured properly:
sudo curl -V # Below is our results. Notice HTTP2 is listed in the Features curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3 Release-Date: 2018-01-24 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL
Even after all above efforts you might still running into issue and your test results shows HTTP2 is not supported. This is due to the fact that Apache 2.4 pmp_prefork module stopped supporting mod_http2, and you’re likely to see this error in your Apache2 error log:
AH10034: The mpm module (prefork.c) is not supported by mod_http2. The mpm determines how things are processed in your server. HTTP/2 has more demands in this regard and the currently selected mpm will just not do. This is an advisory warning. Your server will continue to work, but the HTTP/2 protocol will be inactive.
Since mod_php module uses mpm_prefork module, the workaround is to disable mod_php and and pmp_prefolk and install and enable php-fpm and pmp_event:
sudo systemctl stop apache2 sudo apt-get install php7.1-fpm sudo a2enmod proxy_fcgi setenvif sudo a2enconf php7.1-fpm sudo a2dismod php7.1 sudo a2dismod mpm_prefork sudo a2enmod mpm_event sudo systemctl start apache2
Lastly, test your HTTP2 support, and don’t foget to look into Apache2 error log for any hidden issues.