Open In App

How to Enable HTTP/2 protocol support in Apache?

Last Updated : 25 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

HTTP/2 is a significant update to the HTTP protocol. It was created to outperform HTTP 1.1 in terms of performance and latency. The applications operate way faster and more efficiently if we enable HTTP/2 on our Apache server.

Prerequisites

  • Apache Version: 2.4.17 or later.
  • OpenSSL Version: Ensure OpenSSL version 1.0.2 or later is installed, as ALPN (Application-Layer Protocol Negotiation) support is required for HTTP/2.
  • SSL/TLS: HTTP/2 requires an SSL/TLS connection, so your Apache server must be configured to use HTTPS.

Step to Enable HTTP/2 in Apache

Step 1: Update Apache

Check, your Apache installation is up to date. On Ubuntu or Debian-based systems, you can update Apache using:

sudo apt update
sudo apt upgrade

Step 2: Enabling SSL Module

Enable SSL Module using the following command

sudo a2enmod ssl

Step 3: Enable HTTP/2 Module

Enable the HTTP/2 module in Apache. On Ubuntu/Debian systems.

sudo a2enmod http2

Step 4: Configure Apache to Use HTTP/2

Now, Edit your Apache SSL configuration file.

location:

/etc/apache2/sites-available/default-ssl.conf (Ubuntu/Debian)
/etc/httpd/conf.d/ssl.conf.( windows)
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /var/www/html

SSLEngine on
SSLCertificateFile /path/to/your/certificate.crt
SSLCertificateKeyFile /path/to/your/private.key

Protocols h2 http/1.1

<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Ensure Protocols h2 http/1.1 is added within the VirtualHost block.

Step 5: Restart Apache

After making these changes, restart Apache to apply the new configuration:

sudo systemctl restart apache2 

Step 6: Verify HTTP/2 is Enabled

You can verify that HTTP/2 is enabled using a web browser or an online HTTP/2 checker. For a command-line approach

command:

curl -I -k -s --http2 https://www.example.com

Look for HTTP/2 200 or similar in the output, indicating HTTP/2 support.

Troubleshooting

  • Check Apache Logs: If Apache fails to restart or HTTP/2 is not enabled, check the Apache error logs.

location

/var/log/apache2/error.log (Ubuntu/Debian).
  • Ensure ALPN Support: Verify that your OpenSSL version supports ALPN. You can check your OpenSSL version with openssl version.
openssl version
  • Configuration Errors: Ensure there are no syntax errors in your Apache configuration files by running:
sudo apachectl configtest

Conclusion

If we enable HTTP/2 on Apache server it enhances the performance of application by improving the page time loades. By following this guide steps oulined you can easily enable HTTP/2 in your apache server.


Next Article
Article Tags :

Similar Reads