August 18, 2014
Installing mod_deflate on CentOS 5
By DineEngine
mod_deflate

Performance tuning is a critical component of any large website. The reduction in mere milliseconds could be the difference between a visitor viewing your page, and someone moving on to your competitor. Recently, DineEngine® was contacted to audit and implement changes to a highly-trafficked WordPress site on a LAMP (Linux, Apache, MySQL, PHP) server. During this, we found that the output was not being gzip compressed.

Typically this isn’t any cause for concern. Use your package manager to install mod_deflate, set the appropriate values in Apache’s configuration, and move on to the next item on the list. In this case, however, it wasn’t that simple.

The Environment

  • CentOS 5.10
  • Apache 2.2.19
  • MySQL 5.0.96
  • PHP 5.2

Installing mod_deflate

The server runs Apache 2, so we went searching for mod_deflate, which is preferred over mod_gzip in the 2.x release. Based on other resources online, the consensus was that mod_deflate was already installed on CentOS 5’s version of Apache 2 — this was not the case here.

Initially it did appear that the module was installed correctly on the server. Adding the appropriate AddOutputFilterByType configuration options checked out fine with httpd -t. However, viewing the headers in Chrome’s developer tools, there was no change, which was confirmed by a gzip testing site. Another check with httpd -l showed that it was not, in fact, compiled with Apache, nor was there a mod_deflate.so in the /etc/httpd/modules/ directory.

The next step to try was to do a yum install mod_deflate, which yielded a response of “No package mod_deflate available.” That’s ok, we have another way to install it.

Because the server was also using WHM/cPanel, it had the EasyApache module set up Apache without this module. The plan was to rebuild Apache with the module added, but the wizard to do this would only allow down to PHP 5.3, and the server is running PHP 5.2 (another company implemented the site and made changes of their own, which would possibly break on a PHP upgrade). This removed rebuilding Apache as an option.

The Solution

In the end, we decided that the easiest way to get mod_deflate added was to compile it from source and add it to the modules. We grabbed the Apache 2.2.19 source from the archives and extracted it on the server. From here, it was just a matter of compiling it and loading it in the configuration file.

Compiling the module:

$ cd /usr/local/src
$ wget https://archive.apache.org/dist/httpd/httpd-2.2.19.tar.gz
$ tar zxvf httpd-2.2.19.tar.gz
$ cd httpd-2.2.19/modules/filters
$ sudo apxs -i -c -Wl,lz mod_deflate.c

Added to Apache’s configuration for the site:

LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.[0678] no-gzip
BrowserMatch bMSIEs7 !no-gzip !gzip-only-text/html
BrowserMatch bOpera !no-gzip
Header append Vary User-Agent

DeflateCompressionLevel 9

Restarted Apache with sudo service httpd graceful and that was it!

3 Comments

  1. nazim d

    i installed mod_deflate with your help. i installed 2 more modules by same way.

    i did these :

    cd httpd-2.2.19/modules/metadata

    sudo apxs -i -c -Wl,lz mod_expires.c
    sudo apxs -i -c -Wl,lz mod_headers.c

    i added these to httpd.conf file
    LoadModule expires_module modules/mod_expires.so

    LoadModule headers_module modules/mod_headers.so

    as last :
    sudo service httpd graceful

    as result it gave an error like this :

    module expires_module is built-in and can’t be loaded

    why? can we solve it ?

    thanks.

    Reply
  2. Linerd

    Thanks. This was the only method that worked for me. EasyApache screwed up my WordPress installation and I had to restore from backup.

    I modified the commands for my version of Apache and then I added the module in the main httpd.conf.

    Reply
    • Linerd

      BTW, this was on CentOS 6.

      Reply

Submit a Comment

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

Trusted by top brands.

Get Started with DineEngine.

Contact Us Now Find Out How Chepri Can Help Your Team. Ask Us More About Installing mod_deflate on CentOS 5.

(800) 338-8102

733-C Lakeview Plaza Blvd. Worthington, OH 43085.