Skip to content

How to Enable Gzip Compression in cPanel/WHM Globally

This article will help you to enable apache gzip compression in WHM/cPanel gloablly. Using root access of WHM we can enable mod_deflate globally in WHM.

Steps
3
Category
Web Servers
Covers
Apache, cPanel, tar
On this page 3 steps

Apache mod_deflate module is responsible for the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network. mod_deflate is the replacement of mod_gzip which was used with older version of Apache.

The users with cPanel access only can also enable the Gzip compression. Follow our other article to enable Apache Gzip Compression in cPanel only account.

The users with root access can use the WHM panel and enable Apache mod_deflate globally for all cPanel users. Let’s follow the below steps to enable apache Gzip compression (mod_deflate) for all cPanel accounts.

Step 1 of 3Login to WHM Panel

You must have the root credentials of your system to get access to the WHM panel. It is required to make changes globally in a cPanel server. The default WHM is accessible on 2087 (SSL) and 2086 (non-SSL) ports.

Open a web browser and access the WHM Panel:

https://11.22.33.44:2087

Login with the administrator (root) account.

Step 2 of 3Edit Apache Pre VirtualHost

You need to added your settings in Pre section of Virtualhosts. So it will be loaded by the all Virtualhost in server. Let’s navigate to the below location in WHM:

Home » Service Configuration » Apache Configuration » Include Editor

Edit Pre VirtualHost Include (All versions) as per shown in below screenshot:

cpanel-apache-pre-virtualhost

You may get this box empty for previously added settings.

Step 3 of 3Update Pre VirtualHost

Append the below configuration to the Pre VirtualHost editor and save it. Don’t overwrite any existing configuration, that are added for other purposes.

<IfModule mod_deflate.c>
	# Insert filter
	SetOutputFilter DEFLATE
	<IfModule mod_setenvif.c>
		# 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

		# Don’t compress images
		SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
	</IfModule>

	<IfModule mod_headers.c>
		# Make sure proxies don’t deliver the wrong content
		Header append Vary User-Agent env=!dont-vary
	</IfModule>
</IfModule>

The above configuration has been taken from Here. So read this article carefully before implementing it.

Save the changes and you will get a restart Apache button. Restart Apache service to apply all changes.

Conclusion

In this tutorial, you have learned to enable Gzip compression server-wide (globally) on a WHM/cPanel server. Now, use this link to verify your server gzip using one of domain configured on server.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

32 Comments

  1. Thanks for the information.I had been looking for way to compress content on my website and this by far is the easiest and best.

  2. I cannot thank you enough. It actually works beautifully. You have also explained it in such a easy implementable way. Setting it up was a breeze. I looked for this information earlier also, but couldn’t find anywhere on the net. But I guess I got lucky this time. Just implementing this increase speed up by 10%.

  3. Thank you for this! We have rolled out this globally with our servers! With Deflate sites looks to be working better and faster.

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top