The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Enable gzip / mod_deflate

Discussion in 'General Discussion' started by GoWilkes, Jun 16, 2013.

  1. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I'm setting up a new WHM/cPanel server. Using EasyApache, I've updated Apache to version 2.2.24, and under "Exhaustive Options", I have "Deflate" checked. But the output does not appear to be compressed, and when I look at httpd.conf, I don't find "deflate" referenced anywhere in the file.

    I looked through my old server's httpd.conf file, too (which has Apache 2.0.64), and also didn't find any reference to "deflate". But, it's definitely gzip compressed, according to several online tools. So even though I found a few tutorials online that said to uncomment specific lines in the httpd.conf file, that doesn't seem to be the same thing that I had before, since those lines never existed yet the server was still compressing.

    Just to be clear, I'm wanting to compress everything to use the least amount of bandwidth possible, even if it does create more of a load on the CPU. I have plenty of CPU to spare, but not bandwidth.

    Further, I did find references to adding the following to the top of all pages:

    <?php
    if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
    ob_start("ob_gzhandler");
    else ob_start();
    ?>

    But of course, this has the limitations that:

    1. It only works on PHP pages;

    2. It requires an update to hundreds, maybe thousands of pages; and

    3. It relies on the account owners to continue adding it themselves, instead of it being automatically loaded.

    Any advice on how to enable Gzip or mod_deflate correctly would be very appreciated! TIA,

    Jason
     
  2. ES - George

    ES - George Well-Known Member
    PartnerNOC

    Joined:
    Jun 12, 2011
    Messages:
    142
    Likes Received:
    1
    Trophy Points:
    16
    Location:
    UK
    cPanel Access Level:
    Root Administrator
    Hello :)

    Once mod_deflate has been loaded via EasyApache, it must be activated via the cPanel account that you wish to enable compression for (the Optimize Website icon). I have attached a screenshot which shows this.
     

    Attached Files:

  3. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Thanks, George! I think I knew that once upon a time, but forgot. It's kinda unfortunate that there's not a way to simply do it for all accounts; I can't think of any reason that I wouldn't want an account to be compressed, and I just spent almost 3 hours enabling it manually for 108 different accounts!
     
  4. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Update:

    For others reading this, I just found an article that said you CAN turn on "Optimize Website" globally in WHM. I haven't tried this, to use at your own risk.

    Step 1. Go to Services Configuration >> Apache Configuration >> Include Editor >> Post VirtualHost Include, and select All Versions.

    Step 2: Paste this in to the corresponding file:

    <IfModule mod_deflate.c>
    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 \bMSI[E] !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>
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,694
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page