On Ubuntu and Debian Linux, you can install the Apache server and host your own website. And, if you ever tried to use the Apache webserver on a Red Hat or Fedora Linux, you might know that the HTTP daemon (httpd) runs in your Linux system’s background to transfer the hypermedia and respond to the server’s request. After installing the HTTP daemon on your system, you can enable HTTP/2.0 on your Linux system.
When you allow the HTTP/2.0 service on an Apache server, it enhances your server and client’s response rate. Configuring and enabling the HTTP/2.0 services on an Apache server is easy and straightforward.
Enable HTTP/2 in Apache on Linux
Enabling the HTTP/2.0 requires HTTPS protocols and TLS protocols; make sure that your server is secured with an SSL certification method. To get the SSL certification, you can follow our previous tutorial on the Let’s Encrypt (Certbot) method on your Linux system.
And, also make sure that both your server end and the browser end has the capability to enable the HTTP/2.0 service. Through modern browsers has the inbuilt capability to use the HTTP/2.0 services. In this post, we will see how to enable HTTP/2.0 in the Apache server.
Step 1: Check the Ability To Enable HTTP/2.0
In Linux, to enable the HTTP/2.0 service in the Apache server, you need to have the Apache server 2.4.17 or higher version. To check which version of the Apache server you’re currently using, run the following commands on your terminal shell.
Check Apache Version on Debian/Ubuntu Linux
apache -v
Check Apache Version on Red Hat/Fedora Linux
httpd -v
If you are a Debian Linux user, you can also run the following a2enmod command to ensure your server is integrated with the SSL module.
sudo a2enmod ssl
You can also run the following command on your shell to check if your system has the HTTP2 module installed or not.
sudo a2enmod http2
Step 2: Configure the Apache Server to Enable HTTP/2.0
After making sure that your Apache server has the ability to use the HTTP/2.0 protocols, it’s time to enable the HTTP/2.0 protocol. The process of enabling the HTTP/2.0 on Debian and Red Hat-based Linux systems is pretty the same. Here, we will see how you can configure your Apache server’s script to enable the HTTP/2.0 on your Linux system.
1. Enable HTTP/2.0 in Apache on Ubuntu/Debian
In Ubuntu or other Debian Linux distributions, the configuration script of the Apache server is stored inside the /etc/apache2/ directory. You can find the local configuration script and edit the HTTP protocol from the script. Run the following command on your terminal shell with root access to edit the script. Don’t forget to replace the demo.www.bytesbuzz.com with your server address.
sudo nano /etc/apache2/sites-enabled/demo.www.bytesbuzz.com-le-ssl.conf
Now, add the following HTTP/2.0 protocol at the bottom of the script.
Protocols h2 http/1.1
<VirtualHost *:443> ServerName demo.www.bytesbuzz.com ServerAlias wdemo.www.bytesbuzz.com DocumentRoot /var/www/public_html/demo.www.bytesbuzz.com SSLEngine on SSLCertificateKeyFile /path/to/private.pem SSLCertificateFile /path/to/cert.pem SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1 Protocols h2 http/1.1 </VirtualHost>
Then save and edit the file. You can now restart your Apache server to see the impacts.
sudo systemctl restart apache2
2. Enable HTTP/2.0 in Apache on Red Hat/Fedora
As the Red Hat and Fedora Linux uses the HTTP daemon (httpd) service to run the Apache server, you will be editing the httpd configuration script to enable the HTTP/2.0 protocol on a Red Hat-based system. Before enabling the HTTP protocol, it would help if you got the HTTP2 module and integrate it with your server.
You can run the following DNF command-line on your terminal shell to install the HTTP2 module on your system.
sudo dnf -y install mod_http2
Then restart the HTTP daemon on your Linux system.
sudo systemctl restart httpd
You can now run the following command on your terminal shell with root privilege to edit the Apache configuration script. Here, I’m using the Nano script editor, and you can use your favorite editor to edit the Apache configuration script.
sudo nano /etc/httpd/conf.d/domain-name.com.conf
Once the editor opens, you can now put the following HTTP protocol line inside the script.
Protocols h2 http/1.1
Here, you can follow the demo script to understand where you should put the protocol address. You can put the HTTP/2.0 protocol address at the bottom of the script right before the virtualhost
closing tag.
<virtualhost :443> Protocols h2 http/1.1 ...</virtualhost>
Step 3: Check and Close
After successfully enabling the HTTP/2.0 protocol in the Apache server, it’s now time to check the server’s status. You can check the HTTP protocol from the web browser or run the following cURL command with root privilege. The cURL command would return you the status of the connection type and the HTTP protocol type.
sudo curl -v --http2 https://localhost
To check the HTTP protocol version from the web browser, you need to open your site and right-click on your webpage the open the Inspect Element tab. After opening the element inspection, you can now find the Network monitoring tool to view the version of the HTTP protocol.
Final Words
Enabling the HTTP/2.0 protocol in the Apache server is not a hard task. In the entire post, I have described the methods of installing the HTTP2 modules and enabling the HTTP/2.0 protocol in the Apache server on Linux.
If you find this post useful and informative, please share it with your friends and the Linux community. We also encourage you to write down your opinions regarding this post in the comment section.