..a dose of zero-day know-hows ..

11/19/2007

How to compile/install mod_deflate into Apache 2.x

The following assumptions will be used throughout this article:
  • Apache is installed in /usr/local/apache2 directory
  • Apache Source Code version is 2.0.59
  • Apache Source code is uncompressed in /home/user directory
The three assumptions above will be dependent on your system setup and should be changed in the commands below as(if) appropriate.
  1. Hack apr-config located in the /usr/local/apache2/bin directory so the LDFLAGS will have the "-lz" value similar below:
    LDFLAGS="-lz"
  2. Download and extract apache httpd source code and navigate to the /home/user/httpd-2.0.59/modules/filters directory
  3. Run the following command while in the modules/filters directory:
    /usr/local/apache2/bin/apxs -c mod_deflate.c
  4. Copy the compiled mod_deflate.so into the apache2/modules directory using the following command:
    cp .libs/mod_deflate.so /usr/local/apache2/modules/
  5. Edit the Apache configuration (apache2/conf/httpd.conf) and append the following lines:
    LoadModule deflate_module modules/mod_deflate.so


    # Insert filter
    SetOutputFilter DEFLATE

    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won't work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    # Don't compress images
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    Header append Vary User-Agent env=!dont-vary

  6. Restart apache by invoking the following command while in the apache2/bin directory
    apachectl restart
    if on ssl, stop apachectl first and restart in ssl mode
    apachectl stop
    apachectl startssl

11 comments:

Anonymous said...

Thanks :) its really worked for me.

Rgds
Anand

Arpee Ong said...

Glad to help :)

itguru@gmail.com said...

amazing instructions. Worked for me as well. One question do we need to remove -lz from LDFLAGS after we done? What is it for? As for everything else it worked really well. I went to http://www.whatsmyip.org/http_compression/ to test it, you might want to modify the post so people can test the settings right away.

Thank you so much

Anonymous said...

Very helpful, works ok. Thanks !

Unknown said...

Please receive my congratulations and thanks for a very detailed and efficient post that saved my butt today !
Cheers
Alex

jose said...

Thank you so much, it works for me too

Vidyadhar said...

I want to enable compression in apache. For the same I am trying to use deflate module of apache.

I have already installed apache 2. But it is a default installation and in that mod_deflate is not enable. Now I am compiling mod_deflate module by using following commands:

cd /usr/local/src/httpd-2.2.21/modules/filters/
/usr/local/apache/bin/apxs -i -c -Wl,lz mod_deflate.c

After doing it I have added following line in my httpd.conf file

LoadModule deflate_module modules/mod_deflate.so

but as soon as i do syntax check I am getting following error httpd: Syntax error on line 417 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/mod_deflate.so into server: /usr/local/apache/modules/mod_deflate.so: undefined symbol: inflate

Following is the output of ldd command

linux-gate.so.1 => (0x00b2d000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x008e6000)

Please help as i dont want to compile apache again.

Vidyadhar said...

I want to enable compression in apache. For the same I am trying to use deflate module of apache.

I have already installed apache 2. But it is a default installation and in that mod_deflate is not enable. Now I am compiling mod_deflate module by using following commands:

cd /usr/local/src/httpd-2.2.21/modules/filters/
/usr/local/apache/bin/apxs -i -c -Wl,lz mod_deflate.c

After doing it I have added following line in my httpd.conf file

LoadModule deflate_module modules/mod_deflate.so

but as soon as i do syntax check I am getting following error httpd: Syntax error on line 417 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/mod_deflate.so into server: /usr/local/apache/modules/mod_deflate.so: undefined symbol: inflate

Following is the output of ldd command

linux-gate.so.1 => (0x00b2d000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x008e6000)

Please help as i dont want to compile apache again.

Maycon said...

Thank You! You save my day.

Anonymous said...

Add a - in the linkage command.
/usr/local/apache/bin/apxs -i -c -Wl,-lz mod_deflate.c

Anonymous said...

after setting -lz it shows unable to find liberary -lz.
I am new to this so please help