How to Enable HTTP2.0 in Apache on Ubuntu?

HTTP/2.0 is the latest version of the HTTP protocol that offers significant performance improvements over its predecessor, HTTP/1.1. Enabling HTTP/2.0 on your Apache web server can enhance the speed and responsiveness of your website, resulting in a better user experience for your visitors. In this article, we will guide you through the steps to enable HTTP/2.0 on Apache on Ubuntu.

Prerequisites

Before enabling HTTP/2.0, ensure your system meets these requirements:

  • Apache version 2.4.17 or later with HTTP/2 support

  • SSL/TLS certificate installed (HTTP/2.0 requires HTTPS)

  • Ubuntu server with root or sudo privileges

Step 1: Check Apache Version

First, verify that your Apache version supports HTTP/2.0 by running the following command:

apache2 -v

The output should show Apache version 2.4.17 or later. If your version is older, update Apache before proceeding.

Step 2: Install SSL Certificate

HTTP/2.0 requires a secure SSL/TLS connection. If you don't have an SSL certificate installed, you can obtain a free Let's Encrypt SSL certificate. Install the Certbot client and obtain a certificate:

sudo apt update
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d yourdomain.com

Step 3: Enable HTTP/2.0 Module

Install and enable the HTTP/2 module for Apache:

sudo a2enmod http2
sudo systemctl reload apache2

Step 4: Configure Virtual Host

Edit your Apache virtual host configuration file to enable HTTP/2.0:

sudo nano /etc/apache2/sites-available/your-site.conf

Add the Protocols directive to your SSL virtual host block:

<VirtualHost *:443>
    ServerName yourdomain.com
    DocumentRoot /var/www/html
    
    Protocols h2 http/1.1
    
    SSLEngine on
    SSLCertificateFile /path/to/certificate.pem
    SSLCertificateKeyFile /path/to/private/key.pem
    
    # Other SSL and site configuration...
</VirtualHost>

Step 5: Restart Apache

Test the configuration and restart Apache to apply the changes:

sudo apache2ctl configtest
sudo systemctl restart apache2

Step 6: Verify HTTP/2.0 is Working

Test your HTTP/2.0 configuration using several methods:

Method 1: Browser Developer Tools

Open your website in Chrome or Firefox, press F12, go to the Network tab, and look for the Protocol column showing "h2".

Method 2: Command Line Test

curl -I --http2 -s https://yourdomain.com | grep -i 'HTTP\|protocol'

Method 3: Online Testing Tool

Visit https://tools.keycdn.com/http2-test and enter your domain to verify HTTP/2.0 support.

Performance Optimization

To maximize HTTP/2.0 benefits, consider these optimizations:

Enable Compression

Enable gzip compression to reduce file sizes:

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json
    DeflateCompressionLevel 6
</IfModule>

Enable Caching

Configure browser caching for static resources:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
</IfModule>

Troubleshooting

If HTTP/2.0 isn't working, check these common issues:

Issue Solution
HTTP/2 module not loaded Run sudo a2enmod http2
SSL not configured Ensure SSL certificate is properly installed
Apache version too old Update Apache to version 2.4.17+
Configuration syntax error Run apache2ctl configtest to check

Conclusion

Enabling HTTP/2.0 on Apache significantly improves website performance through multiplexing, header compression, and server push capabilities. With proper SSL configuration and the Protocols h2 http/1.1 directive, your site will automatically serve HTTP/2.0 to compatible browsers while falling back to HTTP/1.1 for older clients, ensuring optimal performance and compatibility.

Updated on: 2026-03-17T09:01:38+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements