Enabling mod_gzip

2 minute read

Glenn asked me how to enable gzip under Apache, so I figured I would write this post so that everyone could benefit.

To start, mod_gzip has to be compiled in to Apache. This is a stable module, last updated in late 2002. It is possible that it is already installed, so let’s check and see.

Checking for mod_gzip

Let’s check to see if mod_gzip is already installed. Visit http://web-sniffer.net/ and enter a URL that will be served from your server. Hit the Submit button and await the response. Scroll down to the section labeled HTTP Response Header, and then look for the line labeled “Server:”. My Server line includes the following text (I added the bold-facing):

Apache/1.3.29 (Unix) PHP/4.3.6 mod_gzip/1.3.26.1a mod_throttle/3.1.2

As you can see from the bolded text, I already have modgzip installed. If your server has modgzip installed, consider yourself lucky (maybe even buy a lottery ticket), and skip down to the section labeled “Configuring mod_gzip.”

Installing mod_gzip

If you do not have modgzip installed, then you have to install it. The exact procedure for doing this will vary depending on the Apache configuration and operating system. I installed Apache using Apache Toolbox, and simply checked the modgzip entry in the appropriate menu. Go ahead and install it as appropriate (there’s no way I can know enough about your system to say any more than this), and then come back here.

Configuring mod_gzip

Now you need to add some entries to your Apache configuration file. On my system this file is called httpd.conf. You will need the following entries: ` modgzipon Yes modgzipminimumfilesize 300 modgzipmaximumfilesize 0 modgzipmaximuminmemsize 100000 modgzipkeepworkfiles No modgziptempdir /tmp modgzipiteminclude mime ^text/.* modgzipiteminclude mime ^application/postscript$ modgzipiteminclude mime ^application/ms.*$ modgzipiteminclude mime ^application/vnd.$ modgzipitemexclude mime ^application/x-javascript$ modgzipitemexclude mime ^image/.$ `

After you have you configuration set, restart Apache and your feeds should now be compressed. If you get any error messages when you restart Apache, double-check to make sure that mod_gzip is installed.

Final Zip Tips

You may find it necessary to make sure that certain files or file types are not compressed by modgzip. For example, I have several dynamic pages on Syndic8. The pages can product incremental output for several minutes, usually while they munch on a long list of submitted feeds. By default, modgzip would wait until pages like these have finished, and the output would appear all at once (after several minutes) instead of incrementally. To make sure that this doesn’t happy, simply tell mod*gzip not to process these files by adding the following line to your configuration file: ` mod</em>gzipitemexclude file suggest.php$ `</p> That’s about it. Post a comment if you have any questions about this.

Updated: