Installing mod_gzip on CentOS 5

CentOS 5 is packaged with Apache 2 which is not compatible with mod_gzip. The module mod_deflate is the Apache 2 equivalent.

Installing mod_deflate on CentOS 5 is a fairly simple process. The module is included in CentOS 5 and just need to be configured.

The only changes required are to the Apache configuration file /etc/httpd/conf/httpd.conf. I recommend that you take a backup before you make any changes.

Here are the steps that I took:

1. Check that the deflate module is loaded.
In my configuration file this was already done with this line:

1
LoadModule deflate_module modules/mod_deflate.so

If this is not there then I suspect all that is required is to add this line. However if you need to do this I recommend that you check the module /etc/httpd/modules/mod_deflate.so is installed.

2. Configure the deflate module
All that was required was to add the following lines to the Apache configuration file.

1
2
3
4
5
6
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
BrowserMatch \bOpera !no-gzip
Header append Vary User-Agent

Update 26/08/2008: Originally I only had the first line of the above configuration. However it turns out that there are issues with Internet Explorer 6 and HTTP compression.

I added this after

1
2
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

but you should be able to add it anywhere in the main section.

3. Restart Apache

1
service httpd restart

4. Test it’s working
The easiest way to check that it is working is with the YSlow plugin for Firebug. Firebug is a Firefox plugin that will give you lots of useful information.

To test just load a page in your browser, go to the Firebug/YSlow plug and select the “Performance” option. This will give you a performance grade. You should hopefully see an “A” for “4. Gzip components”. If not do a Ctrl-F5 to ensure that you’re not viewing cached content.

If this still does not report an “A” for “4. Gzip components”. then it is possible that your page has other content types that need to be added for YSlow to be happy.

Summary
This is only a quick overview of the steps I took, and by no means comprehensive A more detailed tutorial is available here: http://www.howtoforge.com/apache2_mod_deflate

4 Responses to “Installing mod_gzip on CentOS 5”

  1. […] I wrote about installing mod_gzip on CentOS 5. However since then I have discovered that Internet Explorer 6 has does not support this properly, […]

  2. Thanks!

    That worked perfectly for me on CentOS 5.4!

  3. work perfect thanx

  4. Worked for me!

Leave a Reply