Get The Most Affordable Hosting in the World!

Starting at just $1.87/month, Vercaa offers unbeatable pricing for world-class web hosting services.

Fast, reliable, and secure hosting to power your website without breaking the bank. Plus, enjoy a free CDN for faster loading times worldwide!

Get Started Now!

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.

apache gzip test

If you have your own Dedicated Server or Cloud VPS with full root access ro WHM, the 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>

Enable Gzip on WHM for all websites

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.

Alternatively, you can simply use curl from the Linux terminal, like this.
If you see “Content-Encoding: gzip” in the headers, then your content is gzipped. See below:

[webtech@localhost ~]$ curl -H "Accept-Encoding: gzip" -I https://nixcp.com
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 12 Jul 2017 17:47:59 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Link: <https://nixcp.com/wp-json/>; rel="https://api.w.org/"
Strict-Transport-Security: max-age=15724800; includeSubdomains; preload
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Content-Encoding: gzip
[webtech@localhost ~]$

If that code doesn’t work, edit the Pre VirtualHost block again, delete the old code and try this alternative:

# Enable GZIP Compression.

SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

 now you know how to enable gzip compression for all your accounts on a WHM based server.

 

The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.

Was this answer helpful? 1 Users Found This Useful (1 Votes)