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:

LoadModule deflate_module modules/

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/ is installed.

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

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

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

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

3. Restart Apache

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.

This is only a quick overview of the steps I took, and by no means comprehensive A more detailed tutorial is available here:

4 thoughts on “Installing mod_gzip on CentOS 5”

Leave a Reply

Your email address will not be published. Required fields are marked *