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.

Have gzip compression enabled for accounts on the server (including newly created accounts)

Discussion in 'Workarounds and Optimization' started by HostXNow_Chris, Sep 28, 2016.

  1. HostXNow_Chris

    HostXNow_Chris Registered

    Joined:
    Jan 22, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    United Kingdom
    cPanel Access Level:
    Root Administrator
    Hi,

    How to have gzip compression enabled for accounts on the server (including newly created accounts) [Optimize Website in cPanel]

    I know there are ways to enable it with EasyApache 3 but now we're using EasyApache 4 so just wondering if there's a better way without having to update it the old way eg adding code to Apache conf! Is there a new setting to enable it? There should be after all these years :)

    Kind regards,
    Chris
     
  2. linux4me2

    linux4me2 Well-Known Member

    Joined:
    Aug 21, 2015
    Messages:
    83
    Likes Received:
    15
    Trophy Points:
    8
    Location:
    USA
    cPanel Access Level:
    Root Administrator
    In EasyApache4, you can add GZIP compression server-wide, including new accounts, by adding the following to Service Configuration → Apache Configuration → Include Editor → Pre Virtualhost Include → All Versions:
    Code:
    # Enable GZIP Compression.
    <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 \bMSIE !no-gzip !gzip-only-text/html
          
            # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
            # the above regex won't work. You can use the following
            # workaround to get the desired effect:
            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>
    
    I realize there's some out-of-date stuff in there regarding browsers and Apache versions, but it seems to work just fine on my server.

    I have disabled the "Optimize Website" feature in cPanel to make sure users don't unnecessarily add GZIP via their own .htaccess.
     
    cPanelMichael likes this.
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator

Share This Page