How to Add Brotli Support on Apache

cctv 6078897 640

This post shows students and new users step to add Brotli support to Apache when using Ubuntu Linux. Brotli ( br for short), 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 use Apache brotli module. Unlike Nginx, there’s full Brotli support for Apache web server.

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

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

When you’re ready to including 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 how to install 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 don’t already have Apache server installed, then use the steps below to download and install it from Ubuntu repository.

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

We’ve written a great post on how to Install 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 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 you can enable Brotli module for Apache, you must first install it. Brotli package is available in 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 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. If you find any error above or have something to add, please use the comment form below.

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.