Skip to content

Enabling Gzip and Brotli compression on cPanel/WHM

Compression cuts transfer size by 60–80% on HTML, CSS, and JS, and every modern browser supports both. Here is how to turn it on under Apache, LiteSpeed, and Cloudflare.

Compression should be on by default on every cPanel host, but on roughly a third of the servers we take over, it is either disabled at the web server level or being stripped by an upstream proxy. The fix is two lines of config; the impact is a measurable improvement to LCP and to bandwidth costs. Brotli compresses about 15–20% better than Gzip on text, so we enable both with Brotli preferred when the client supports it.

What’s happening

Apache mod_deflate provides Gzip; mod_brotli provides Brotli. LiteSpeed has both built into the core server, configured through the WebAdmin or httpd_config.conf. When a browser sends Accept-Encoding: gzip, br, the server picks the strongest algorithm it has compiled support for and compresses the response on the fly. The catch: compression is CPU work. On a busy shared host, compressing every response to every visitor every time can add measurable load. Caching the compressed copy at the CDN or at LSCache eliminates the repeat cost.

How to verify

From outside the host:

curl -I -H "Accept-Encoding: gzip, br" https://example.com/
curl -I -H "Accept-Encoding: gzip, br" https://example.com/wp-content/themes/site/style.css

Look for content-encoding: br (Brotli) or content-encoding: gzip in the response. If neither appears, compression is off or being stripped. To distinguish, check the host directly:

curl -I -H "Accept-Encoding: gzip, br" --resolve example.com:443:127.0.0.1 https://example.com/

If the local response has compression but the public one does not, an upstream (Cloudflare, a reverse proxy, a load balancer) is stripping it.

The fix

On Apache, enable both modules through WHM > Apache Configuration > Global Configuration, or via EasyApache 4 directly. Then in .htaccess:

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript text/xml application/xml application/json
</IfModule>
<IfModule mod_brotli.c>
  AddOutputFilterByType BROTLI_COMPRESS text/html text/css application/javascript text/xml application/xml application/json
</IfModule>

On LiteSpeed, compression is enabled in Tuning > GZIP/Brotli Compression. Set Brotli compression level to 5 (a sane CPU/ratio tradeoff) and Gzip to 6. Anything higher uses more CPU than it saves bandwidth.

For Cloudflare-fronted sites, leave server-side compression on (Cloudflare passes it through) and enable Brotli in Cloudflare’s Speed settings. Do not double-compress. Stack Harbor configures compression and verifies it through a real client as part of managed cPanel operations.