Force GZIP compression on your HostMonster-hosted website
As you may already know, I am a speed and performance junkie. When it comes to website management, nothing makes me feel better than a website that loads fast! If this can be done with dynamic content then it is something to admire.
One feature that I have implemented on the HostMonster-hosted website that I manage is GZIP compression. For a detailed description on GZIP you can read this very interesting article on BetterExplained.com. In short, however, what GZIPing does is that it compresses downloaded files which essentially saves a bit on server bandwidth and slightly speeds up client-side viewing. Although you can use some PHP to call for compression on the fly for specific files it is much easier to simply activate compression from the web server. Here, I will show you how you can activate it for a website hosted with HostMonster. This should also work if you are on another shared hosting provider that runs under Linux and Apache. You need access to your php.ini file and .htaccess file.
- Check to make sure that your hosting environment can utilize GZIP. If you host your website with HostMonster this feature is supported. On other web hosts you will need to execute phpinfo(), then ensure that ‘gzip‘ is listed under _ENV["HTTP_ACCEPT_ENCODING"] and HTTP_ACCEPT_ENCODING to verify.
- Once you have verified that the feature is supported go ahead and create a single php.ini file that can be applied to all subdirectories within your /htdocs or /public_html directory. On HostMonster-hosted, just go to the ‘Software/Services’ section of your cPanel and click on ‘PHP Config’. Select ‘PHP5 (single php.ini)’ and save the change. Then, click on “Install PHP.ini master file”. Rename the “php.ini.default” file to php.ini in your public web files directory. If you had one there before, delete it before renaming the new php.ini file.
- Open the php.ini file in a simple text editor and navigate to the section that deals with . Set the value equal to ob_gzhandler and ensure that any values for zlib are disabled or commented out. Afterward, save and update the php.ini file on the server.
output_handler = ob_gzhandler zlib.output_compression = Off ;zlib.output_handler =
- Open the .htaccess file that is located in your public web files directory (usually the same location as you php.ini file). Add the following statements to invoke the use of the relevant Apache module for compressing your files listed and save.
- Now try accessing your website through your browser. After about a minute or two, run the GIDZipTest for your website. If your site is reported to be serving compressed pages then you are finished!
I have been able to achieve compression as high as 70% as reported by the GIDZipTest page. I hope it works for you and your site sees a bit more improvement when it comes to loading time. There are still a few other things that can be done in terms of making things faster, but those will come later. Happy tweaking!
WARNING: Do not attempt to enable GZIP using these steps while you have ZLIB enabled. Use one or the other. Again, HostMonster supports ZLIB but, just like GZIP, it is not enabled by default. Furthermore, attempting to enable server-side compression while you have PHP or plugins already doing the compression can lead to a garbled output.