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.
- CentOS 5.10
- Apache 2.2.19
- MySQL 5.0.96
- PHP 5.2
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.
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:
Restarted Apache with sudo service httpd graceful and that was it!