1

VPS Hosting : Utilising Gzip Compression

Overview

Gzip compression is a quick and simple method of speeding up page load times for visitors to your site.  Its very simple, rather than send the browser a 100k file with the html (or css or javascript) for a page its quicker to compress the page on the server, send the compressed data, then have the browser uncompress it.  Trust me it is, even with broadband connections it is still expensive in terms of resources to transmit data to the end user.

There is an overhead involved with compressing data on the fly, it increases the cpu load on the server (or vps), however in almost all cases there is spare CPU capacity, whereas in many cases for our VPS customers bandwidth is at a premium (so two reasons to do this!)

Complexity

Easy.

Suitable for:

Any VPS!

Although its possible that this will conflict the Fooman Speedster for Magento as everything else does.

Requirements

Administrator Access to your Hosting Control Panel, we're going to use the File Manager within the Virtuozzo Power Panel to make the changes.
Alternatively these changes could be made with root shell access.

Howto :

We are going to add an Apache Web Server configuration file to the VPS, this means we have to edit files as root and restart Apache.  If the file is not edited correctly then Apache will not restart.  To fix this you will only need to remove the file and restart Apache again.  We recommend you follow the instructions carefully to prevent this happening.

1) In contrast to the shared hosting guide (See the Shared Hosting forum) we don't really care whether your site is currently using compression or not, as we are going to make the configuration change at a higher level, thereby applying gzip compression to every site on the VPS and also speeding up the compression process (albeit only by a few milliseconds per file).

2) In your Hosting Control Panel navigate to the Virtuozzo File Manager (Login (as administrator) -> Virtuozzo Side Bar Option -> File Manager).

2.1) Navigate to /etc/httpd/conf.d/ by clicking on each directory in turn.

2.2) Once there, click on the Create File option.

2.3) Create a file named mod_deflate.conf and with the following content :

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html 
AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/xml 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE text/javascript 
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

2.3) Click on Create to save the file. NOTE The file must end with .conf as that is how the Apache Web Server identifies its configuration files.

3) Now navigate back into the main section of the Hosting Control Panel to the Service Management page (Server Sidebar Option -> Service Management)

3.1) Restart the Apache Web Server (Click on the far right hand orange button on the Web Server (Apache) row)

4) Wait a few moments then test your sites are all working.  Then test for gzip compression here

Possible Issues :

If all your sites stop working then its most likely a typing error or extra digits in the mod_deflate.conf file that we created.  Return to the Virtuozzo File Manager and using the pencil icon on the mod_deflate.conf row edit and check the file.  If you can't see any errors then save the file and simply delete it.  Then restart Apache again.

If not all your sites are affected then try renaming the .htaccess file for the site not working to see if that resolves the issue.  If it does there are overlapping or conflicting compression rules in the .htaccess and by judicious editing of the .htaccess you should be able to resolve the problem.

Failing that, its likely you have a site that is based on some very old web application software and you'll have to revert back.  You can however follow the shared hosting version of this guide that utilises the .htaccess on a per site basis to provide gzip compression.


Reversing the Change

Delete the /etc/httpd/conf.d/mod_deflate.conf file and restart your Apache Web Server.

Further Reading

This article does a very good job of explaining how gzip compression works and also links out to other useful articles.