Apache mod_deflate module is one of the best friends of a cPanel system administrator. It allows you to save bandwidth and accelerate page speed response by deflating output filter from your server to be served compressed (gzipped) before it goes back to the client.

mod_deflate is the modern replacement for the old mod_gzip, which was used to compress – gzip web pages in the first versions of Apache like 1.3.x

How can I enable Gzip on WHM for all my cPanel accounts / domains?

cPanel comes by default with Apache 2.4, and on this kind of servers it’s pretty easy to enable Apache Gzip compression for all your server accounts.

If you have your own Dedicated Server or Cloud VPS with full root access to WHM, then you can enable Apache mod_deflate globally for all your cPanel users. This tutorial will show you how to activate Gzip compression for Apache on cPanel using mod_deflate.

1. Login to WHM

Move to WHM control panel login, access with your root credentials from:

https://111.222.333.444:2087/

Replace 111.222.333.444 with your real server IP address.

2. Edit Apache Configuration

On the left menu, search for:

  • Home » Service Configuration » Apache Configuration » Include Editor
  • Edit “Pre VirtualHost Include (All versions)” block.

3. Update Pre VirtualHost

Add this code to your Pre VirtualHost include, as you see below.

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

4. Restart Apache and Verify

After adding that code into your Apache configuration, make sure to hit Update button, so all the settings can be saved. Then hit the Restart button to apply the changes.

5. Verify Gzip is working on all your sites

You can use sites like gzip test to verify if all your WHM websites are using the mod_deflate configuration you specified.