In this tutorial, we will show you how to enable brotli compression. For those of you who didn’t know, Brotli is a new compression format launched by Google which claims to save 20%-28% over their previous gzip or and mod_deflate compatible implementation, for similar speeds. Brotli has the advantage that for the same amount of CPU work a smaller compressed file is created. This magnifies the advantages of using compression to serve site content. Brotli compression is supported by all the major browsers like Chrome, Firefox, Safari, and Microsoft Edge.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you through the step-by-step enabling Brotli Compression on Apache webserver. You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Enable Brotli Compression on Apache
Step 1. First, make sure that all your system packages are up-to-date by running the following
apt commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing Brotli on Ubuntu.
Now run the following command below to install Brotli on your system:
sudo apt install brotli
Step 3. Enable Brotli Compression on Apache.
Next step we enable the brotli module in Apache with the following command:
sudo a2enmod brotli
After that, configure the Apache virtual host by adding the following code to the virtual host configuration file:
Example VirtualHost file:
Save the file and restart the Apache service to apply changes:
sudo systemctl restart apache2
Step 4. Test Brotli.
Once successfully install and setup, you can check your server headers with
curl -I -H 'Accept-Encoding: br' http://your-domain.com
HTTP/1.1 200 OK Date: Thu, 01 Sep 2021 06:26:54 GMT Server: Apache/2.4.46 (Ubuntu) Upgrade: h2,h2c Connection: Upgrade Last-Modified: Fri, 10 Mei 2021 22:46:36 GMT ETag: "33-5ba9m3ilanacdf-br" Accept-Ranges: bytes Vary: Accept-Encoding Content-Encoding: br Content-Length: 36 Content-Type: text/html
Congratulations! You have successfully installed the Brotli module. Thanks for using this tutorial to enable Brotli on Ubuntu 20.04 LTS (Focal Fossa) system. For additional help or useful information, we recommend you check the official Apache website.