Jump to content

how to compress website contents when gzip and zlib mods are enabled?


qtriangle

Recommended Posts

Hello friends,

 

I am trying to compress contents of my website using gzip method.

 

I searched on web, and came to know that I need to do following 2 things to enable gzip compression:

 

1. putting php.ini file with following contents in document root :

 

output_handler=ob_gzhandler
zlib.output_compression = Off

 

2. putting following lines in .htaccess file:

<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>

 

But, doing above 2 things does not compress the website contents.

My website is http://www.greathosts.in

and I am checking the compression at http://www.gidnetwork.com/tools/gzip-test.php

It tells me contents are not compressed.

 

However, if I remove the condition

IfModule mod_gzip.c

, it gives me "500 Internal server error".

 

So, it looks to me that gzip module is not enabled on Apache indeed.

 

My hosting provider says he has enabled gzip and zlib compression, and there is something wrong with the above code.

 

I have had a very long discussion with the hosting provider, but he keeps on telling that it is a problem with the scripting, and no problem with server configuration.

 

Please help to point out if  I am doing anything wrong.

 

Thanks

Saurabh

http://www.qtriangle.in

http://www.economichosting.net

Link to comment
Share on other sites

"I searched on web, and came to know that I need to do following 2 things to enable gzip compression:"

 

Do 1 or the other.  Doing it twice means that the content might be double gzipped.

 

 

Also, what version of Apache is it?  If it's 2, then you probably need mod_deflate, not mod_gzip.

Link to comment
Share on other sites

thanks for your reply Corbin, but it does not work even if I make 1 change at a time.

 

Looks like I got it working, using this entry in php.ini:

 

zlib.output_compression = On

 

but I have to put a php.ini in EVERY directory whose contents I want compressed.

 

If anyone can suggest a better approach, like some change in .htaccess, so that I dont have to put lots of php.ini, would be appreciated.

 

Of course, none of the earlier mentioned methods work for me.

 

Thanks,

Saurabh

http://www.qtriangle.in

http://www.economichosting.net

Link to comment
Share on other sites

Hi Corbin,

PHP version is 5.2.11

 

This code

<?php print_r(apache_get_modules());  ?>

 

Gives me this:

 

Fatal error:  Call to undefined function apache_get_modules() in a.php on line 1

But in phpifo(), I see following:

 

HTTP_ACCEPT_ENCODING gzip,deflate 
_SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate
_ENV["HTTP_ACCEPT_ENCODING"] gzip,deflate

 

Does this information help in any manner?

 

Thanks a lot for your suggestion,

Link to comment
Share on other sites

That accept encoding stuff is client side.

 

Hrmmm, you could try this:

 

<IfModule mod_deflate>

    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

</IfModule>

 

The easiest way to check if mod_deflate is enabled or not would be to just remove the IfModule and leave the AddOut... line and see if it's a 500 error.  (The 500 error from the mod_gzip stuff means that most likely mod_gzip is not enabled.)

 

Do you happen to know what version of Apache is running?  An easy way to determine that is either phpinfo() or do the following in command prompt:

 

telnet yourwebsite.com

HEAD / HTTP/1.1

Host: yourwebsite.com

Connection: close

 

(Double enter after it)

 

And see if there is a Server: line in response.

Link to comment
Share on other sites

This is kind of random, but how are you checking if it's compressing the page or not?

 

If there's not an error when you remove that, you seem to have mod_deflate installed.

 

 

Hrmm, instead of doing it by mime type, you could try:

 

<FilesMatch "\\.(js|css|html|htm|php|xml)$">

SetOutputFilter DEFLATE

</FilesMatch>

 

(http://brightscape.net/blog/compress-your-web-pages-with-mod_deflate/)

Link to comment
Share on other sites

Hmmmm....  I bet Apache is setup to not allow that in .htaccess files...

 

You might have to go the PHP route.

 

 

A possible way to do it site wide though could be to use (in an htaccess file):

 

php_flag zlib.output_compression on

 

(Chances are though, if you can't do it the other way, you can't do it this way either.)

 

 

Maybe you should ask your host how they suggest you set it up?  Basically if they've given you access to do it with Apache directives or if you'll have to do it on a PHP level.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.