How to enable gzip or deflate globally in cPanel / WHM

This will be a quick one folks.  The Apache module mod_deflate helps in reducing the size of the information sent to a user, by compressing things prior.  It seems to work very well.  To test if your site already has mod_deflate installed and working, you can go here:

http://www.whatsmyip.org/http_compression/

To enable mod_deflate on your WHM / cPanel server, make sure you run EasyApache through WHM, and select to install mod_deflate.  Once done, you’ll notice that it is not active globally.  In your cPanel control panel for your domain, you should notice that under “Software / Services” an icon called “Optimize Website” is now there.  This is how you control mod_deflate on a per user basis.

If however, you wish enable it globally, so that all websites on your server can benifit from this, you need to venture back into WHM, and this time go to:

Services Configuration >> Apache Configuration >> Include Editor >> Post VirtualHost Include, and select All Versions

Now, paste the following into this file, and hit Update:


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

That’s it, now, go back to the site I gave you at the start, load up your website, and verify that compression is now functioning.

For you command line users, you can achieve this my running the easy apache command line build (/scripts/easyapache), and select to include mod_deflate.  Once that is done, you can edit the “/usr/local/apache/conf/includes/post_virtualhost_2.conf” file, and paste the above code into it to achieve the same results.  Remember to restart apache once you’ve edited the file

  • 336 Users Found This Useful
Was this answer helpful?

Related Articles

cPanel Port Usage

Here is a table of all of the ports used by cPanel. Optional services are noted. If you know...

How to enable gzip in WHM cPanel

Use easyapache to recompile apache and php. Find and enable the module "deflate"Some things to...

Increase cPanel Securetmp Partition Size

cPanel's new securetmp script is handy to prevent users from executing malicious code in /tmp or...

Add a MySQL Database in cPanel

The following article explains how to add a MySQL database in cPanel. You can use cPanel's...

How to globally disable directory browsing on a WHM cPanel server

For those looking for a more simple point and lick solution from WHM. Log into WHM Service...