HTTP/2, often touted as the future of web protocols, brings a multitude of benefits, including multiplexing, server push, and header compression. These advancements not only enhance the speed of web page loading but also improve overall server performance, making HTTP/2 a must-have for any competitive website.

Advertisement

However, running HTTP/2 on Apache, especially on an Ubuntu server, involves more than just a simple switch. It requires an environment that supports this protocol. Notably, HTTP/2 operates exclusively over TLS (HTTPS), making it mandatory to have an SSL/TLS certificate. Additionally, Apache’s default Multi-Processing Module (MPM), mpm_prefork, is not compatible with HTTP/2. This necessitates a switch to a more suitable MPM like mpm_event, which is designed for high-performance, scalable network applications.

This article provides a comprehensive guide on how to enable HTTP/2 on Apache in Ubuntu, focusing on key steps like updating your server, verifying Apache versions, switching from mpm_prefork to mpm_event, enabling necessary modules, and configuring your server to fully leverage the benefits of HTTP/2. Whether you’re managing a small blog or a large e-commerce site, these insights will help you boost your site’s performance and user experience, keeping you at the forefront of web technology advancements.

Enable HTTP2.0 in Apache

Prerequisites

  • Ubuntu server (18.04 or newer)
  • Apache 2.4.17 or later
  • Root or sudo privileges
  • A valid SSL certificate (as HTTP/2 requires HTTPS)

Step by Step Guide

  1. Update Your System
    Before proceeding, ensure your Ubuntu server is up-to-date. Run the following commands:
    sudo apt update && sudo apt upgrade  
    
  2. Verify Apache Version
    HTTP/2 support is available in Apache 2.4.17 and later. Verify your Apache version with:
    apache2 -v 
    

    If your version is older, update Apache:

    sudo apt install apache2 
    
  3. Disable mpm_prefork Module
    The mpm_prefork module is not compatible with HTTP/2. Disable it:
    sudo a2dismod mpm_prefork 
    
  4. Enable mpm_event Module
    The mpm_event module is more efficient and compatible with HTTP/2. Enable it:
    sudo a2enmod mpm_event 
    
  5. Enable Apache HTTP/2 Module
    Apache comes with an HTTP/2 module (mod_http2) that needs to be enabled. Execute:
    sudo a2enmod http2 
    
  6. Configure Apache to Use HTTP/2
    Edit the Apache configuration file to enable HTTP/2. For each virtual host that should use HTTP/2, add Protocols h2 http/1.1 to the configuration. An example for default SSL configuration:
    sudo nano /etc/apache2/sites-available/000-default-le-ssl.conf 
    

    Add Protocols h2 http/1.1 under the <VirtualHost *:443> section.

    
    <VirtualHost *:443>
        ...
        Protocols h2 http/1.1
        ...
    </VirtualHost>
    
    
  7. Test Configuration
    After editing the configuration file, check for syntax errors with:
    sudo apache2ctl configtest 
    

    If the output is Syntax OK, restart Apache to apply changes:

    sudo systemctl restart apache2 
    
  8. Verify HTTP/2 and mpm_event Activation
    Ensure HTTP/2 is active using browser tools or online services. Confirm mpm_event is running with:
    apachectl -M | grep mpm 
    

    To confirm that HTTP/2 is enabled, you can use browser developer tools or online tools like HTTP/2 Test.

    Step-by-Step Guide to Enable HTTP/2.0 in Apache

Conclusion

Enabling HTTP/2 in Apache on Ubuntu can greatly improve the loading times and efficiency of your website. By following these steps, you can leverage the benefits of the latest web protocol standards.

Share.

4 Comments

  1. Now edit your website VirtualHost and add http2 keyword in listen section.

    What kind of instruction is this? it’s useless

Leave A Reply

Exit mobile version