kieranbarnes Independent PHP, WordPress & CubeCart Programmer

Enabling mod_deflate/gzip globally on cPanel

Posted on January 26, 2010

There's far too many reasons to mention why you should enable mod_deflate to gzip your content served by Apache. Simply put, it makes it go fast.

You can enable mod_deflate in cPanel really easily with /scripts/easyapache. Easy.

Once built, you need to tell it to do something. You'll see a new icon on your sites cPanel now, called "Optimize Site". You can enable it on a per site basis.

Thats all very well, but most users won't know that feature and they will annoy you saying their site isn't very fast.

Lets enable it globally to save any hassle.

You will need to edit your Post VirtualHost Include. In WHM;

  • Apache Configuration
  • Include Editor
  • Select All Versions of Post VirtualHost Include
  • Paste the following below
  1. <IfModule mod_deflate.c>
  2. AddOutputFilterByType DEFLATE text/html text/plain text/xml
  3.  
  4. <IfModule mod_setenvif.c>
  5. # Netscape 4.x has some problems…
  6. BrowserMatch ^Mozilla/4 gzip-only-text/html
  7.  
  8. # Netscape 4.06-4.08 have some more problems
  9. BrowserMatch ^Mozilla/4.0[678] no-gzip
  10.  
  11. # MSIE masquerades as Netscape, but it is fine
  12. # BrowserMatch bMSIE !no-gzip !gzip-only-text/html
  13.  
  14. # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
  15. # the above regex won’t work. You can use the following
  16. # workaround to get the desired effect:
  17. BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html
  18.  
  19. # Don’t compress images
  20. SetEnvIfNoCase Request_URI
  21. .(?:exe|t?gz|zip|bz2|sit|rar)$
  22. no-gzip dont-vary
  23. SetEnvIfNoCase Request_URI .pdf$ no-gzip dont-vary
  24.  
  25. </IfModule>
  26.  
  27. <IfModule mod_headers.c>
  28. # Make sure proxies don’t deliver the wrong content
  29. Header append Vary User-Agent env=!dont-vary
  30. </IfModule>
  31. </IfModule>

Restart apache and enjoy.

You can use tools such as YSlow or Google Page Speed to diagnose your gzip savings.


Related posts

  1. Apache2 mod_deflate
    The mod_deflate module provides the DEFLATE output filter that allows output from your server to...
  2. cPanel Apache Tuning
    One of the first things I do is run /scripts/easyapache and rebuild my PHP /...
  3. Anonymous apache & PHP for cPanel
    So I've started playing with cPanel/WHM recently. I've got to say it does make my...
  4. Installing mod_evasive on cPanel and/or Apache
    This guide details how to install mod_evasive on cPanel to help protect against DDOS attacks,...
  5. mod_geoip Revisted including stopping spam in phpBB 2
    I've recently moved a client's forum onto a new cPanel server, previously it was on...

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.