qtriangle Posted December 30, 2009 Share Posted December 30, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/ Share on other sites More sharing options...
corbin Posted December 30, 2009 Share Posted December 30, 2009 "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. Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986121 Share on other sites More sharing options...
qtriangle Posted December 31, 2009 Author Share Posted December 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986310 Share on other sites More sharing options...
corbin Posted December 31, 2009 Share Posted December 31, 2009 Hmmm... Do print_r(apache_get_modules()) on a PHP page (assuming you're running PHP 5), and tell me if mod_gzip or mod_deflate is installed. Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986537 Share on other sites More sharing options...
qtriangle Posted January 1, 2010 Author Share Posted January 1, 2010 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, Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986678 Share on other sites More sharing options...
corbin Posted January 1, 2010 Share Posted January 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986695 Share on other sites More sharing options...
qtriangle Posted January 1, 2010 Author Share Posted January 1, 2010 in phpinfo(), the apache version displayed is "Apache/2.2.14 (Unix)" under "SERVER_SOFTWARE ". I have added the lines suggested by you to .htaccess, but it does not compress the pages. If I remove Ifmodule, there is no error. Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986704 Share on other sites More sharing options...
corbin Posted January 1, 2010 Share Posted January 1, 2010 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/) Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986713 Share on other sites More sharing options...
qtriangle Posted January 1, 2010 Author Share Posted January 1, 2010 Hi Corbin, Thanx for your quick response again. The new directive also does not compress the web pages. I am using http://www.gidnetwork.com/tools/gzip-test.php to check whether web pages are compressed or not. Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-986725 Share on other sites More sharing options...
corbin Posted January 4, 2010 Share Posted January 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/186699-how-to-compress-website-contents-when-gzip-and-zlib-mods-are-enabled/#findComment-988379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.