Enable Apache Gzip Compression (mod_deflate) Globally in WHM/CPanel for All Domains

Enable Apache Gzip Compression (mod_deflate) Globally in WHM/CPanel for All Domains


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.
If you are having only cPanel access (user interface), Then read following article to enable Apache Gzip Compression in account.
If you have root access of WHM, you can enable Apache mod_deflate globally in WHM for all cPanel users. This article will help you to do so. If you are doing or existing server, you may read and understand about its working and impacts on running sites. Follow the below steps to enable apache gzip compression ( mod_deflate ) settings for all cPanel accounts.

Step 1: Login to WHM Panel

For making changes globally, its necessory to have WHM root access. Login to your WHM system
https://11.22.33.44:2087/ 

Step 2: Edit Apache Configuration Pre VirtualHost

Navigate to following location in WHM
Home » Service Configuration » Apache Configuration » Include Editor
and edit Pre VirtualHost Include (All versions) as per below screenshot.
cpanel-apache-pre-virtualhost

Step 3: Update Pre VirtualHost

Add the following settings in Pre VirtualHost editor and update it. Below settings has been taken from Here. So read this article carefully before implementing it.
<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>

Step 4: Restart Apache and Verify

After updating settings in Apache , it will show an restart Apache button. Restart Apache service to complete the setup. You can use this link to verify your server gzip using one of domain configured on server.
It works for cloudlinux as well. 
*Thanks for tecadmin

Post a Comment

0 Comments