When trying to enable HTTP/2 on Apache 2.4.29 (Ubuntu 16.04), many developers hit a fundamental compatibility wall. The issue stems from Apache's Multi-Processing Module architecture:
# Check current MPM
apache2ctl -V | grep -i mpm
# Typical output for problematic setups:
Server MPM: prefork
HTTP/2 requires multiplexed connections handled by a threaded/event-driven MPM. mpm_prefork's process-based model can't support this. Here's the technical breakdown:
# This configuration WON'T work:
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0
You have two viable approaches:
Option 1: Switch to mpm_event
The modern recommended approach:
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo a2enmod http2
sudo systemctl restart apache2
Option 2: PHP-FPM Alternative
For shared hosting environments where mod_php is required:
# Install PHP-FPM
sudo apt-get install php-fpm
# Configure Apache to use FastCGI
SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
After making changes, verify with:
curl -I --http2 https://yourdomain.com
# Look for:
HTTP/2 200
Here's a working httpd.conf snippet:
Protocols h2 h2c http/1.1
H2Direct on
ServerLimit 16
StartServers 2
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 10000
When trying to enable HTTP/2 on Apache 2.4.29 (Ubuntu 16.04), many developers hit a wall despite following the standard procedure:
sudo a2enmod http2
And adding the protocol directive:
Protocols h2 http/1.1
The primary issue stems from using mpm_prefork
module. HTTP/2 requires a threaded MPM (Multi-Processing Module) to function properly. Here's why:
- HTTP/2 multiplexing requires threads to handle concurrent streams
- Prefork creates separate processes (not threads) for each request
- Modern protocols need modern server architectures
The solution is to migrate to mpm_event
module:
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo systemctl restart apache2
Verify the change with:
apache2ctl -M | grep mpm
For PHP on shared hosting, you'll need to consider alternative handlers since php-fpm
is the recommended approach:
sudo apt install php-fpm
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.0-fpm # Adjust version as needed
Here's a working configuration for HTTP/2 with PHP support:
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/html
Protocols h2 http/1.1
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
Confirm HTTP/2 is working:
- Browser DevTools: Check Network tab protocol column
- Command line:
curl -v --http2 https://yoursite.com
- Online tools: KeyCDN HTTP/2 Test
If you're limited to mod_php
on shared hosting and can't change MPM modules:
- Contact your host about enabling HTTP/2
- Consider upgrading to a VPS with more control
- Implement HTTP/2 via CDN (Cloudflare, etc.)