Gzip compression not working

Amit

Verified User
Joined
Mar 24, 2020
Messages
129
Location
India
hi
i am using gzip compression in htaccess with following code but not working php version is 7.2 please help
# BEGIN GZIP COMPRESSION
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP COMPRESSION
 
Hi,
Please guide how would i enable gzip compression many of clients shifting to cpanel because they are not able to implement gzip in directadmin as pingdom or other speed testing tools require gzip on website.
 
Do you have mod_deflate or mod_gzip installed?

Code:
[root@host ~]# cat /usr/local/directadmin/custombuild/custom/ap2/configure.apache | grep "deflate\|gzip"
    "--enable-deflate" \
[root@host ~]# grep -Ri "gzip\|deflate" /usr/local/directadmin/custombuild/configure/ap2/configure.apache
    "--enable-deflate" \
[root@host ~]#

Also, how are you testing?

Certain testing sites will not detect compression correctly when testing the landing page due to some content on that landing page not being compressed. It may be better to test a URL of a resource you know you have declared to be compressed, such as html, for example. Like hXXp://domain.tld/readme.html if using WordPress.
 
I believe cPanel uses deflate for compression via the Optimize Website interface. Correct me if I'm wrong. To do this with Apache on DirectAdmin:

1) Enable mod_deflate in Apache if not already enabled. To check if it is enabled:

Code:
httpd -M | grep deflate

Enable if not:

https://help.directadmin.com/item.php?id=191

2) Add the appropriate .htaccess rules to the site's .htaccess file:

Code:
# COMPRESSION
# BEGIN DEFLATE COMPRESSION
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
</IfModule>
# END DEFLATE COMPRESSION
# END COMPRESSION

Test a specific resource within the site that you have explicitly enabled caching for, such as an html file, for example, domain.tld/readme.html for WordPress.
 
Hi @scriptkitty

I would also like to attempt this but would like to apply it to the whole server, not just a particular users site. When you say to add the rules to the site's .htaccess, are you referring to the servers .htacess here or a particular user's .htacess?

PS - Does anyone have step-by-step instructions that are up-to-date? I found some tutorials for DirectAdmin dating back quite a few years. It seems to be important enough to warrant a gzip option being added to Custombuild 2, in my opinion.

Regards

2) Add the appropriate .htaccess rules to the site's .htaccess file:
 
Have you tried testing a certain resource type that is explicitly set to be compressed yet?
 
gzip compression is enabled by default. I'd suggest opening DirectAdmin ticket if it doesn't work as expected.
 
Man, DirectAdmin is just awesome! I was looking into adding the mod_deflate rules via the http-includes.conf file, and then saw your comment @smtalk and this:

Code:
[root@host custombuild]# cat /etc/httpd/conf/extra/httpd-deflate.conf
#
# Required modules: mod_deflate
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/mod/mod_deflate.html>
# for further details before you try to setup deflate module.
#

<Location />
# Insert filter
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

# Don't compress images and other uncompressible content
SetEnvIfNoCase Request_URI \
 \.(?:gif|jpe?g|png|rar|zip|exe|flv|swf|mov|wma|mp3|mp4|avi|mp?g)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
[root@host custombuild]#

I learn something awesome about DirectAdmin everyday...
 
I
gzip compression is enabled by default. I'd suggest opening DirectAdmin ticket if it doesn't work as expected.
I am using internal license no support available please suggest what to do
 
Internal license means you can contact your provider for support, and if they do not know what to do - they could contact DA for support then.
 
Back
Top