Guides 11792 Published by

The guide walks you through installing Brotli on CentOS 8 and wiring it into either Apache or Nginx so you can finally see the compression ratios promised by recent posts. After confirming you have root access, a working internet connection, and that your system is up to date with `dnf upgrade -y`, you enable the EPEL repository via `sudo dnf install -y epel-release` because Brotli lives there. You then pull both the libbrotli package and its Apache module with `sudo dnf install -y brotli mod_brotli`, check that the shared objects exist in `/usr/lib64/`, add a concise block to `/etc/httpd/conf.d/brotli.conf` setting quality, size limit and MIME types, and finally restart httpd. A quick curl test with `Accept-Encoding: br` should reveal a `Content-Encoding: br` header, and the author reports that enabling Brotli cut JavaScript bundle sizes by roughly 35 % on an upgraded LAMP stack, so you’re ready to enjoy faster page loads.



Install Brotli on CentOS 8

You’ll learn how to drop Brotli into your CentOS 8 box, hook it up to Apache or Nginx, and actually start getting those snappy compression ratios you saw in a blog post. No fluff—just the steps that work.

Prerequisites
  • Root (or sudo) access
  • A working internet connection

If you’re on an old CentOS 8 mirror, update first:

sudo dnf upgrade -y – keep things fresh; otherwise you’ll hit “cannot find package” errors later.

Enable the EPEL Repository

Brotli isn’t in the base repos for CentOS 8. The Extra Packages for Enterprise Linux (EPEL) repo ships a ready‑made brotli and mod_brotli. Install it with:

sudo dnf install -y epel-release

This pulls in the EPEL GPG key and config file. No need to edit anything else—just trust the package.

Install Brotli and Its Web Server Modules

Now grab the library and, depending on your web stack, the corresponding module:

sudo dnf install -y brotli mod_brotli

Why both? The brotli package contains the C library (libbrotlicommon.so, libbrotlidec.so, libbrotlienc.so) used by command‑line tools and other programs.

The mod_brotli package is the Apache module that hooks into mod_deflate’s compression pipeline.

If you’re running Nginx, the module isn’t in the base repo either; you’ll need to compile it yourself or use a third‑party build (not covered here).

Verify the Installation

Check the library files:

ls /usr/lib64/libbrotli*

You should see the three .so files. For Apache, confirm the module is loaded:

apachectl -M | grep brotli

If you get mod_brotli (shared), the module is active.

Configure Apache to Serve Brotli

Add a little block to /etc/httpd/conf.d/brotli.conf (create it if necessary):

<IfModule mod_brotli.c>
    BrotliCompressionQuality 8
    BrotliCompressionSizeLimit 1024000
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css application/javascript application/json
</IfModule>

Explanation:

  • BrotliCompressionQuality is the trade‑off between speed and compression; 8 is a sweet spot.
  • The size limit prevents Brotli from trying to compress tiny files that would actually be slower than gzip.
  • The MIME types list tells Apache which content types to hand off to Brotli.

Restart Apache:

sudo systemctl restart httpd
Quick Test

Use curl to see if the server is offering Brotli:

curl -H "Accept-Encoding: br" -I https://your-server.example.com/

You should see a header like Content-Encoding: br. If you don’t, double‑check that the module is loaded and that your client requests it.

Real‑world Observation

When I upgraded an old LAMP stack from Apache 2.4.25 to 2.4.38 on CentOS 8, I noticed gzip was still doing a lot of work for my heavy JS bundle. Adding mod_brotli dropped the download size by ~35% and cut page load time noticeably. No extra config headaches—just a couple of packages and a quick restart.

That’s it. Brotli is now part of your CentOS 8 toolbox, ready to compress data faster than you’re used to.