Gzip compression is a great tool by web servers with which we can cutdown the size of the pages sent out. In this topic I am discussing on how to enable gzip compression in Apache. Enabling compression means the web server will compress the size of the pages there by we can achieve better speed and low bandwidth usage.
[the_ad id=”11935″]
This can be achieved as follows:
Enable mod_deflate in Apache
- Add the “Deflate” Apache module via EasyApache
- Under WHM >> Service Configuration >> Apache Configuration
- Click Include Editor
- Under Pre VirtualHost Include select “All Versions” and add following lines to the code box:
<IfModule mod_deflate.c> SetOutputFilter DEFLATE # 1 - 9, with 9 as highest level of compression DeflateCompressionLevel 9 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 BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|mov)$ \ 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
<IfModule mod_headers.c>
# Make sure proxies dont deliver the wrong content Header append Vary User-Agent env=!dont-vary </IfModule> </IfModule> - Update and restart apache
This will enable deflate module in the server. Now we need to enable it in the cPanel of the domain which we need to enable compression.
Enable compression in cPanel
- Login to cpanel.
- Under Software/services section click Optimize Website.
- Choose out of the following options to enable or disable gzip compression.
Disabled Compress all content Compress the specified MIME types
- Click Update settings.
To test if gzip compression is working as expected you can use following tool: http://www.whatsmyip.org/http_compression/
Tip: Possible MIME types include text/html, text/plain, text/xml, text/css, text/javascript, application/javascript, application/xhtml+xml, application/xml, application/rss+xml, application/atom_xml, application/x-javascript, application/x-httpd-php, application/x-httpd-fastphp, application/x-httpd-eruby, and image/svg+xml.
Having compression enabled may conflict and generate a blank or scrambled page if you have enabled compression already in the source code of your website.
Leave a Reply