Monday, July 2, 2012

BitNami WordPress now with Varnish Cache

We have just updated BitNami WordPress to version 3.4.1 This version bundles a ready-to-use version of Varnish Cache. 

Varnish Cache is a web application accelerator (also known as a caching HTTP reverse proxy) that can be installed and configured in front of any HTTP server and takes care of caching the content being served. This blog post will show you how to configure a BitNami WordPress Amazon micro instance to use the Varnish for improving the performance.

By default, Varnish is disabled. You can enable it by renaming the control script:

$ cd /opt/bitnami
$ sudo mv /opt/bitnami/varnish/scripts/ctl.sh.disable /opt/bitnami/varnish/scripts/ctl.sh
$ sudo ./ctlscript.sh start varnish

Varnish is installed with a default configuration file, agnostic to the web application being cached. Using this configuration file, although achieving high performance, could lead to some contents not bring properly refreshed in the cache so your users would get an outdated version of your site. The solution is to use a customized VCL configuration file. A good source is the Varnish examples page. In this example, we will change our default.vcl configuration file to a WordPress-specific one (you can find the source file here).

$ sudo mv wordpress.vlc /opt/bitnami/varnish/etc/varnish/

Varnish runs on port 81 by default. You may want to change it to port 80 and change Apache to a different port. We are going to use port 81 for Apache and port 80 for Varnish in this example. You will need to perform the following changes in the server configuration files:

/opt/bitnami/apache2/conf/httpd.conf

Listen 80  change to  Listen 81

/opt/bitnami/varnish/scripts/ctl.sh

VARNISH_PORT=81 change to VARNISH_PORT=80

/opt/bitnami/varnish/etc/varnish/default.vcl where it is specified the Apache port.

backend default {
    .host = "127.0.0.1";
    .port = "80";  change to  "81"
}     

You can now restart the servers:

$ sudo /opt/bitnami/ctlscript.sh restart

In our real life tests running WordPress on an Amazon Web Services micro instance server, a Varnish-enabled instance was able to accommodate between 5 and 10 times more simultaneous users than a vanilla WordPress server.

7 comments:

  1. But this only cache static content, how about dynamic content?

    ReplyDelete
    Replies
    1. Varnish does cache dynamic content.

      Delete
    2. When i execute varnishtop I have this error:

      Error opening terminal: xterm.

      Any ideas?

      Delete
    3. Can you check if this solve your issue? http://answers.bitnami.org/questions/4612/error-using-tput-unknown-terminal-xterm-color

      Thanks.

      Delete
    4. It has not worked. I have the same error when I execute the commands:

      varnishhist
      varnishtop
      varnishsizes
      varnishstat

      If I execute tput I have this error:
      tput: unknown terminal "xterm"

      Thanks

      Delete
  2. The problem is in the TERMINFO. The workaround is:

    Adding export TERMINFO=/usr/share/terminfo in the
    /wordpress-3.4.1-0/scripts/setenv.sh works ok.

    ReplyDelete
  3. why not memcache ?? Why varnish?

    ReplyDelete