Install Brotli in Apache on Debian 11June 22, 2022
Brotli is a new open-source compression format from google that improves on the performance of gzip in many cases, it only only works on an https connection. Enabling Brotli Compression means that your site files are shrinking and moving faster to visitor devices. Even someone with a slow internet connection or a mobile device with limited bandwidth can easily download your site.
Brotli has a general application so it can compress any type of file without destroying the data. However, it is not suitable for image files such as PNG, JPG, and GIF. These types of files are already compressed, and Brotli actually makes them bigger. You can try an image compression plugin instead.
Google’s Brotli is the new replacement for the old gzip and deflate compression. It is a revolutionary open source compression algorythm created by Google engineers. A Brotli study conducted by Gooogle confirmed that it can help to achieve up to 25% more compression ration for files than traditional gzip/deflate methods. It also uses less CPU, which helps to reduce server load significantly.
Before installing getting started, you should already have install Ubuntu on your instance and have install Apache2.4 running as your web server with HTTPS. Apache has supported brotli since version 2.4.26 by way of the mod_brotli module. Check Apache version using this command on your terminal console.
In Debian 11 you will get an output similar to the one below.
Server version: Apache/2.4.53 (Debian)
Server built: 2022-03-14T16:28:35
Update all available repositories on your system and install the Apache webserver using the apt command below.
sudo apt update && sudo apt upgrade -y
Installing Brotli binary
Run the following comnands
sudo apt-get install brotli -y
And your done.
Apache ships with the brotli module and so it just needs enabling:
service apache2 restart
Now we need to add the configuration so that Apache knows when to use brotli. You can put this configuration in either the VirtualHost file of a particular website or into the main configuration for all your sites:
Paste this configuration inside the file
service apache2 restart
sudo a2dismod deflate
Check brotli is working
The best way to check if brotli is working is by using this simple website tool at GiftOfSpeed.com.
That should do it!