Gzip compression helps the webserver to provide the smaller file size and hence the website loads more faster. It will help us to improve the website performance as well as to save the bandwidth.
You need to enable Apache mod_deflate module first in order to enable Gzip compression. You can find the mod_deflate module is enabled on the server by using the following command.
root@server [~]# httpd -M | grep deflate deflate_module (static) root@server [~]#
If it is not enabled, you can enable it by running EasyApache.
The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network. You can read more about mod_deflate module from here.
Generally, you can enable Gzip compression on a particular cPanel account by enabling the “Optimize Website” option. Please check the screenshot.
Also, you can enable Gzip compression globally on cPanel server by adding some settings on Apache configuration. The below steps will help you to enable it globally.
Step 1: Login to your WHM.
Login to the server with the root user.
Step 2: Edit Pre VirtualHost
Please go to:
WHM »Service Configuration »Apache Configuration »Include Editor »Pre VirtualHost Include
and select all versions.
Step 3: Add the following on 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 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 3: Restart Apache
Please restart Apache webservice in order to make the changes in effect.
Step 4: Verify
You can check the Gzip compression by clicking this link.
If you like this post and wish to receive more articles from us, please like our FB page: Grepitout
Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.
For more details on our services, please drop us an E-mail at email@example.com