Today, I’ll show you how to enable the new HTTP/2 protocol on an Apache server running Ubuntu 22.04, although this will work for any server running Apache version 2.4.26 or higher. HTTP/2 delivers web content in binary format as opposed to HTTP/1.1 that uses ASCI text. If you want to take a deep dive into the HTTP/2 protocol, I have given some links at the end of this guide.
This article is part of my series The Ultimate Web Server.
Key Points on HTTP/2- Headers are compressed, reducing load time
- Multiplexing allows for multiple requests over a single TCP connection
- Considered more mobile-friendly
- Improved security as HTTP/2 is only delivered over a HTTPS connection
Contents
- Prerequisites
- Enable HTTP/2 on Apache
- Configure PHP Modules
- Enable MPM EVENT
- Test if HTTP/2 is Enabled
- Conclusion
- See Also
- Further Reading
Prerequisites
- A cloud server (DigitalOcean, Vultr or DreamHost)
- A non-root user with
sudo
privileges (See Initial server set-up) - An Ubuntu 22.04 LAMP server or any LAMP server running Apache 2.4.26 or higher (See How to install LAMP stack on Ubuntu 22.04)
- A registered domain name (Buy one for $0.99 cents from Namecheap)
- A valid, in-date SSL certificate installed for your domain (see Install a free Let’s Encrypt SSL certificate on Ubuntu LAMP stack)
Check Apache Version
To see what version of Apache web server you’re using, login to your web server as your non-root user and use the following command:
apache2 -v
If your version of Apache is 2.4.26 or higher, you’re good to go.
Enable HTTP/2 on Apache
Let’s enable the Apache HTTP/2 module:
sudo a2enmod http2
If you’ve been following my guide The Ultimate Web Server then you’ll already have an Apache Virtual Host file for your website. If not, replace the file name below with default-ssl.conf
.
Open your website’s configuration file (replace ricbre.com
with your domain name):
sudo nano /etc/apache2/sites-enabled/ricbre.com-le-ssl.conf
Just below the <VirtualHost *:443>
tag, type or copy/paste the following code:
Protocols h2 http/1.1
Then save ctrl + o, ENTER and exit nano
ctrl + x.
To apply the changes, restart Apache web server:
sudo systemctl restart apache2
Configure PHP Modules
We need to find what PHP version you’re running. Enter the following and take note of the result (mine is version 8.1):
php -v
Now we install the php-fpm
module:
sudo apt-get install php-fpm
We need to disable mod_php
, so enter the following but replace 8.1
with your PHP version:
sudo a2dismod php8.1
Enable the PHP-FPM mod but again, replace 8.1 with your version:
sudo a2enconf php8.1-fpm
Then we enable the proxy_fcgi
mod:
sudo a2enmod proxy_fcgi
Enable MPM EVENT
By default, Apache will use the mpm_prefork
which is not compatible with HTTP/2, so we need to replace it with the newer mpm_event
module:
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
Then we restart Apache:
sudo systemctl restart apache2
Test if HTTP/2 is Enabled
Let’s check if HTTP/2 was successfully enabled by using the curl
command (replace ricbre.com
with your domain name):
curl -I --http2 -s https://www.ricbre.com/ | grep HTTP
If you see status HTTP/2 200
then your server is fully configured and working with the HTTP/2 protocol.
Conclusion
Hopefully everything went well and your LAMP server is running on HTTP/2 protocol. If you have any questions or need help, hit me up on socials, email or comments.
See Also
- Initial server set up on Ubuntu 22.04 cloud instance
- How to install LAMP stack on Ubuntu 22.04
- How to configure Apache Virtual Hosts on Ubuntu 22.04
- How to install a free Let’s Encrypt SSL certificate on Ubuntu 22.04 LAMP stack
- How to install phpMyAdmin on Ubuntu 22.04 LAMP stack
- How to secure an Ubuntu 22.04 LAMP Stack
- How to install WordPress on Ubuntu 22.04 LAMP stack
Comments
There are currently no comments on this article.
Comment