How to Add Brotli Support on Apache

|

|

The post instructs how to add Brotli support to Apache on Ubuntu Linux. Brotli, an open-source compression algorithm by Google, compresses data more efficiently than other algorithms. To use Brotli with Apache, the Apache Brotli module needs to be activated. Apache should have SSL support before using Brotli, achievable using Let’s Encrypt. Steps include installing…

This post shows students and new users how to add Brotli support to Apache when using Ubuntu Linux. Brotli is an open-source compression algorithm developed by Google that can be used as an alternative to Gzip, Zopfli, and Deflate. In some studies, data can be compressed by 10 to 20 percent more than current compression algorithms.

If you want to use Brotli with Apache, you’ll have to enable the use Apache brotli module. Unlike Nginx, there’s full Brotli support for the Apache web servers.

This post was tested on Ubuntu Linux but should apply to other Linux distributions. I selected Ubuntu because it’s easy to use, especially for new users.

Also, for students and new users learning Linux, Ubuntu Linux is the easiest place to start learning. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices.

When you’re ready to include Brotli support with Apache, follow the steps below:

How to install Let’s Encrypt SSL on Ubuntu Linux

Brotli requires SSL. Apache will need to have SSL support before you’ll be able to use Brotli. Since Let’s Encrypt is easy to install and use with Ubuntu, we’ve written a great post on installing a Let’s Encrypt free SSL certificate.

Click on the post below to learn how to install Let’s Encrypt free SSL certificates on Ubuntu Linux.

How to install Let’s Encrypt on Ubuntu Linux with Apache

How to Install Apache on Ubuntu Linux

If you haven’t already installed an Apache server, use the steps below to download and install it from the Ubuntu repository.

Installing Apache on Ubuntu Linux is pretty straightforward. Apache package is in Ubuntu repositories, so all one needs to do is run the apt-get command to install it.

We’ve written a great post on installing Apache on Ubuntu Linux. Click on the post below to learn how to install and configure Apache on Ubuntu Linux.

How to install Apache on Ubuntu Linux

How to install and enable the Apache Brotli module

At this point, you should have Apache installed with Let’s Encrypt support. If you haven’t already done so, refer to the steps above.

Before enabling the Brotli module for Apache, you must first install it. Brotli package is available in the Ubuntu default repository.

Simply run the commands below to install Brotli.

sudo apt install brotli

Once Brotli is installed, run the commands below to enable the Apache Brotli module.

sudo a2enmod brotli

Next, add the directive to Apache virtual host to enable Brotli support. You need to add the below code in the virtual host configuration file.

<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
</IfModule>

An example example.com.conf virtual host configurations should look similar to the one below.

<VirtualHost *:80>
      ServerAdmin admin@example.com
      ServerName example.com
      DocumentRoot /var/www/
 
      <IfModule mod_brotli.c>
            AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript
      </IfModule>
 
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

When you add Brotli support above, run the commands below to restart Apache.

sudo systemctl restart apache2

You can text Brotli support using the curl command against your domain.

curl -I -H 'Accept-Encoding: br' http://example.com 

That should do it!

Conclusion:

This post showed you how to enable Brotli support on Apache. Please use the comment form below if you find any errors above or have something to add.


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



Leave a Reply

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

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading