1 min read

Enable & Use HTTP/2 with Digital Ocean LAMP

Required: An Ubuntu 22.04 LAMP server or any LAMP server running Apache 2.4.26 or higher 

Enable HTTP/2 on Apache

First check the Version of Apache by using this command in your terminal.

apache2 -v

Enable HTTP2

sudo a2enmod http2

Open your website’s configuration file (replace domain.com with your domain name):

sudo nano /etc/apache2/sites-enabled/domain.com-le-ssl.conf

Just below the <VirtualHost *:443> tag, type or copy/paste the following code:

Protocols h2 http/1.1

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 domain.com with your domain name):

curl -I --http2 -s https://www.domain.com/ | grep HTTP

If you see status HTTP/2 200 then your server is fully configured and working with the HTTP/2 protocol.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.