Thursday, October 7, 2010

Compile apache 2 with mod_deflate on Linux


I have always had trouble finding a simple "How to" to compile apache with exactly what I needed, meaning the common modules plus the mod_deflate. It turns out it is very simple. And that is probably why no one has bothered putting down the steps.

This installation will install apache 2.0.63 and zlib 1.2.5, on an ubuntu 10.04 machine. But I can rather safely presume, that the following steps will be the same for any *nix that has already installed the c compiler.

First of all, I downloaded the latest apache source package from httpd.apache.org [ http-2.0.63.tar.gz ].

Next , I downloaded the latest zlib source package from zlib.net [ zlib-1.2.5.tar.gz ].

I copied both packages inside /opt/packages and run the following commnads from a terminal:

cd /opt/packages
tar -xvf httpd-2.0.63.tar.gz
tar -xvf zlib-1.2.5.tar.gz

cd zlib-1.2.5
./configure –prefix=/usr/local/zlib
make
sudo make install

cd ../httpd-2.0.63

(The following three lines is one command. Just copy it with the slashes and it will run correctly. Slash tells the terminal that the command will continue in the next line!)
./configure --prefix=/usr/local/apache2 \
--enable-mods-shared="all" --enable-deflate \
–with-z="/usr/local/zlib"

make
sudo make install

So zlib is now installed in /usr/local/zlib and apache inside /usr/local/apache2 which are the default install locations.

And now to enable mod_deflate for most common files by editing httpd.conf:

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/javascript application/x-javascript

I hope this little "how to" will save you a lot of time and trouble.
Especially for all of you making your first steps with apache.
 

p.s.
You can find me on fiverr for more personalized requests on any java app server configuration problem or java error that you encounter, with deliverance of less than a day (true!) and money back guarantee if not satisfied.