How to Add Brotli Compression Support on Apache

How to Add Brotli Compression Support on Apache

This brief guide shows how to add Brotli compression support on Apache on Ubuntu Linux. If you are a beginner or a new user and want to add Brotli support for Apache on your ubuntu Linux machine then this short tutorial is useful and handy for you.

Brotli is an open source lossless compression algorithm developed by Google. It works best for text compression and also alternative to Gzip, Zopfli and Deflate.

Brotli fully support Apache Web Server. If you plan to use Brotli with Apache on Ubuntu then you will need to enable Apache brotli module.

Ubuntu is a Linux Operating System based on Debian and mostly composed of non-profit(free) and open-source software. It is a complete Linux operating system that compatible with desktops, laptops, server and other devices. Ubuntu is Open Source so it is freely available for both community and professional support.

if you are a learner and looking for a Linux distribution for Learning then Ubuntu Linux Operating System is best for you as a beginning.


Add Brotli Compression Support on Apache

When you are ready, follow the steps below to add Brotli Compression Support on Apache:

Step 1 : Install Let’s Encrypt SSL on Ubuntu Linux

Brotli compression support requires SSL certificate. You will need to install SSL certificate with Apache in order to use Brotli.

In this tutorial, we are going to install and use Let’s Encrypt SSL Certificate on Ubuntu Linux with Apache.

Let’s Encrypt is a certificate authority that provides non-profit and Free SSL/Transport Layer Security encryption(TLS) certificate. This authority run and managed by Internet Security Research Group (ISRG).

To install and use Let’s Encrypt free SSL certificates on Ubuntu Linux with Apache, simply click on the link below:

How to Setup Let’s Encrypt SSL Certificate on Ubuntu Linux with Apache


Step 2 : Install Apache on Ubuntu Linux

Run the commands below to install Apache2 HTTP on Ubuntu server:

sudo apt update
sudo apt install apache2

Next, run the commands below to stop, start and enable Apache2 service to always start up with the server boots:

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

For check if Apache2 server is installed or not, simply open your browser and type server IP or hostname.

If browser show result similar like below then Apache2 is installed and working properly.

http://localhost
apache-default-page

Step 3 : Install Apache Brotli module on Ubuntu Linux

For the Ubuntu users, Brotli package is available in the Ubuntu official repository. So open the terminal and run the command below to install Brotli :

sudo apt install brotli

The command above will install the Brotli package in your Ubuntu Linux system.


Step 4 : Enable and Configure Brotli with Apache

sudo a2enmod brotli

Next, add the below code in the Apache virtual host configuration file to enable compression with Brotli support:

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

After adding the configuration settings, the Virtual host configuration file looks similar like 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>

Restart the Apache service to apply the changes by using the command below:

sudo systemctl restart apache2

Step 5 : Test Brotli Compression Support

You can use the curl command to test Brotli support:

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

Replace the example.com with your own domain.


That’s all

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

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.

Scroll to Top