How To Enable GZIP Compression In cPanel WHM

Have you ever wondered How To Enable GZIP Compression In cPanel WHM?

I moved servers earlier this year at the same host provider and lately I noticed my sites were somewhat slower. That’s odd for a more powerful server with more memory, so I started digging around.

It turns out that I forgot to migrate my pre_virtualhost_global.conf file that ensured all sites on my dedicated server were compressing content to browsers. I’ve had a dedicated server for over 10 years and it boggles my mind that I still forget to do some basic things.

If you don’t have a VPS or Dedicated server, don’t worry – you may still be able to enable GZIP compression (it depends on your provider).  The first section is for those with only cPanel access (not WHM) and further down those with a VPS or Dedicated server will find instructions.

Check your site to see if GZIP compression is already enabled: http://checkgzipcompression.com/

If your site does not have GZIP compression enabled, then read on to enable GZIP compression.

 

cPanel Access Only (no WHM or root access)
If you only have cPanel access and do not have access to WHM as a root user, then this section is for you.

Log into your cPanel account for the domain, type “optimize” (no quotes) in the search bar, and click “Optimize Website”.

cpanel-optimize-website

You’ll see this:

cpanel-optimize-website-compress-enable-gzip-compression

It’s currently set to Disabled, which gives you no benefit at all.  You can either select “Compress All Content” (does all except images) OR the last option “Compress the specified MIME types”.

If you select the last option, replace the text there with the selection directly below this, and click “Update Settings”:

text/html text/css text/javascript text/xml text/plain image/x-icon image/svg+xml application/rss+xml application/javascript application/x-javascript application/xml application/xhtml+xml application/x-font application/x-font-truetype application/x-font-ttf application/x-font-otf application/x-font-opentype application/vnd.ms-fontobject font/ttf font/otf font/opentype

 

cPanel/WHM (root access)

If you have a VPS or Dedicated server, then this is how you enable GZIP compression for all sites on the server.

Log into your cPanel/WHM interface, type “Apache” in the upper left search bar, click “Apache Configuration”, click “Include Editor”, under “Pre VirtualHost Include” click the dropdown and select “All Versions”, paste the text below in the box, click Update, and allow the system to rebuild the configuration and restart Apache – that’s it.  Now all sites on your server have GZIP compression enabled.

cpanel-apache-configuration-enable-gzip-compression

cpanel-apache-configuration-include-editor-enable-gzip-compression

 

Paste this in the “Pre VirtualHost Include” box:

<IfModule mod_deflate.c>
# Insert filter
SetOutputFilter DEFLATE

# Level of compression (Highest 9 – Lowest 1)
DeflateCompressionLevel 9

#OPTIONAL – add a custom log to store compression info – handy to see
#DeflateFilterNote Input input_info
#DeflateFilterNote Output output_info
#DeflateFilterNote Ratio ratio_info
#LogFormat ‘”%r” %{output_info}n/%{input_info}n (%{ratio_info}n%%)’ deflate
#CustomLog logs/deflate_log DEFLATE

<IfModule mod_setenvif.c>
# Netscape 4.x has issues
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 has issues
BrowserMatch ^Mozilla/4.0[678] no-gzip

# MSIE
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

# Don’t compress images and other files already compressed
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png|ico)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .flv no-gzip dont-vary
</IfModule>

<IfModule mod_headers.c>
# Ensure proxies deliver the correct content
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>

 

That’s it!  In either scenario you now have GZIP compression enabled for one or more websites on your server.

If for some reason you can’t do either of these, then you might want to get a new web host.

Click To View Shared Hosting Reviews »

Disclaimer: A great deal of effort goes into maintaining a website like this and at the time of writing we believe the data was correct, but is provided without any warranty. It is your responsibility to to check the official website for their current offers, terms, details, and other useful information. We receive compensation from many of the offers displayed and that may or may not influence how and where these offers are displayed (including the order). We do not have all available offers for many reasons. All opinions we express on the site are solely ours and are not approved or provided to us by the companies.