mod-gzip – How To Download pages faster and Save Server Bandwidth

I recently ran these pages through a Web Optimiser and the speeds were not that impressive, so I have decided to implement mod_gzip. This will compress the textual portion of these pages so that they download quicker.

The procedure will NOT follow the familiar procedure for those who follow this site, so read on…

  • Download the source from Sourceforge.net using the command wget, for example wget http://easynews.dl.sourceforge.net/sourceforge/mod-gzip/mod_gzip-1.3.26.1a.tgz. Choose the mirror nearest to your server. If you are running Apache 2.0, then you will need to donload the module from here instead.
  • Unzip this file and extract the contents so that we can get on with the build gunzip -c mod_gzip-1.3.26.1a.tgz | tar x
  • Change into the source directory cd mod_gzip-1.3.26.1a.
  • The directions for building mod_gzip are included at the end of the ChangeLog file.

    There are two ways to build mod_gzip:

    1. statically compiled into Apache and
    2. a DSO-File for mod_so.

    The DSO-Version is much easier to build. Just type

    make APXS=/path/to/apxs
    make install APXS=/path/to/apxs
    /path/to/apachectl restart

    The apxs script is normaly located inside the bin directory of Apache.

    The path to APXS is /usr/local/apache/bin/apxs or /usr/sbin/apxs, so we will use the command
    make APXS=/usr/sbin/apxs >log.make 2>err.make
    NOTE:You will get an error complaining about ok_to_send being unused. This Warning can be safely ignored.
    mod_gzip.c: In function `mod_gzip_sendfile2':
    mod_gzip.c:5262: warning: unused variable `ok_to_send'

  • The final step of the build process is to install the module. This will copy the library to the relevant place and edit your httpd.conf file.
    make install APXS=/usr/sbin/apxs >log.install 2>err.install
    The installer inserted two lines into the httpd.conf file, which are commented out. However, it did not quite get it right on my system, so it is just as well that they are commented out! The lines read

    <IfDefine HAVE_FRONTPAGE_SPHERA>
    LoadModule frontpage_module modules/mod_frontpage_sphera.so
    #LoadModule gzip_module /usr/lib/apache/mod_gzip.so
    </IfDefine>

    and should have read


    <IfDefine HAVE_FRONTPAGE_SPHERA>
    LoadModule frontpage_module modules/mod_frontpage_sphera.so
    </IfDefine>
    <IfDefine HAVE_GZIP>
    LoadModule gzip_module /usr/lib/apache/mod_gzip.so
    </IfDefine>

    The variable HAVE_GZIP is automatically created by the start up process. The installer also made the same mistake with the AddModule directives which read
    <IfDefine HAVE_FRONTPAGE_SPHERA>
    AddModule mod_frontpage_sphera.c
    #AddModule mod_gzip.c
    </IfDefine>

    instead of

    <IfDefine HAVE_FRONTPAGE_SPHERA>
    AddModule mod_frontpage_sphera.c
    </IfDefine>
    <IfDefine HAVE_GZIP>
    AddModule mod_gzip.c
    </IfDefine>

  • There are still a couple of changes to make to the httpd.conf file according to Apache’s own website. The following needs to be added to the configuration file; I added it just after the AddModule (within the define block)
    mod_gzip_on Yes
    mod_gzip_can_negotiate Yes
    mod_gzip_dechunk Yes
    mod_gzip_minimum_file_size 600
    mod_gzip_maximum_file_size 0
    mod_gzip_maximum_inmem_size 100000
    mod_gzip_keep_workfiles No
    mod_gzip_temp_dir /usr/local/apache/gzip
    mod_gzip_item_include file \.html$
    mod_gzip_item_include file \.txt$
    mod_gzip_item_include file \.jsp$
    mod_gzip_item_include file \.php$
    mod_gzip_item_include file \.pl$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-httpd-php
    mod_gzip_item_include mime ^httpd/unix-directory$
    mod_gzip_item_include handler ^perl-script$
    mod_gzip_item_include handler ^server-status$
    mod_gzip_item_include handler ^server-info$
    mod_gzip_item_exclude file \.css$
    mod_gzip_item_exclude file \.js$
    mod_gzip_item_exclude mime ^image/.*

    Additional filetypes can be defined. For example, there is no need to compress PDF files as they are already compressed, so we could also add
    mod_gzip_item_exclude mime ^application/pdf$
  • You will also need to create the mod_gzip_temp_dir specified in httpd.conf. mkdir /usr/local/apache/gzip
  • Next restart Apache and check that everything is still working. If you get the error
    Syntax error on line xxx of /etc/httpd/conf/httpd.conf:
    Cannot add module via name 'mod_gzip.c': not in list of loaded modules
    then you forgot top remove the # from the LoadModule command or mod_glib.so is not in the correct directory.

One thought on “mod-gzip – How To Download pages faster and Save Server Bandwidth

  1. Don’t forget to install the “GNU Compiler Collection 1.0″ from the Westhost manager or you will get errors.

Comments are closed.