Have gzip compression enabled for accounts on the server (including newly created accounts)
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
-
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: # Enable GZIP Compression. SetOutputFilter DEFLATE # 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 # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary
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.0 -
Hello @HostXNow_Chris, The steps in the previous response should work. Let us know if you have any additional questions. Thanks! 0 -
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:
# Enable GZIP Compression. SetOutputFilter DEFLATE # 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 # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary
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.
Thanks a lot this really save me some time!0 -
Sorry for bumping such an old post but does anyone know if there's a way I can adapt this to work for all but one account on our server? The account in question has a script that doesn't work with GZIP enabled but I'd very much like it to be turned on for everyone else. 0 -
Thanks for the info! I'm still struggling to make this work, though. I tried this just now. I added the appropriate info through WHM for all hosts and then created the /etc/apache2/conf.d/userdata/ssl/2_4/{username} and /etc/apache2/conf.d/userdata/std/2_4/{username} directories. I then made a file called pre_virtualhost.conf and put it into both directories, rebuilt the HTTPD conf and restarted Apache, but this didn't seem to work. GZIP is still enabled for all domains under that username along with all others on the server. The includes are definitely being processed, as I deliberately put a typo into them and tried to rebuild the conf and it didn't work. Any ideas why this wouldn't be working? For what it's worth I tried inserting this code immediately after the block I'd just added into the pre_virtualhost include file through WHM and it didn't seem to work there, either. Thanks again! 0 -
Hello @davidatfuzzylim, Could you let us know what method you are using to test if compression is enabled? Thank you. 0 -
Hi, I tried both Check GZIP compression and Google's Pagespeed Insights tool to check this. 0 -
Hello, You could try using an entry like this in the /etc/apache2/conf.d/userdata/std/2_4/exampleuser/example.tld/no-deflate.conf file: SetOutputFilter DEFLATE # Don't compress PHP or HTML SetEnvIfNoCase Request_URI .(?:php|html)$ no-gzip dont-vary
Remember to run the following command after making the change:/usr/local/cpanel/scripts/ensure_vhost_includes --all-users
Then, check to see if PHP and HTML files are compressed. Note that you can change this custom entry to suite your own preferences. Thank you.0 -
Perfect, that did the trick! Thanks. 0 -
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:
# Enable GZIP Compression. SetOutputFilter DEFLATE # 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 # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary
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.
Does this work with Apache 2.4.x? I do not use Apache 2.0.48 anymore"# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48"0 -
Hello @vlee, Yes, the full entry works for Apache 2.4. Thank you. 0 -
Hello @vlee, Yes, the full entry works for Apache 2.4. Thank you.
Thank you0 -
A lot of good feedback here. Great stuff. 0
Please sign in to leave a comment.
Comments
14 comments