\

WordPress under Nginx and Varnish with W3TC

I decided to switch to a Virtual Private Server (VPS) so that I could have more flexibility and control over my server environment. I selected VM Storm based on a review of “low-end” VPS providers (since this is my personal tinkering platform I don’t need to pay extra for a high-end name). I then added Nginx as my Web server, Varnish as a front-end cache, WordPress for blogging, and W3TC as a WordPress performance enhancer.

By Kristopher A. Nelson in

Twitter Facebook

When it comes to my personal Internet presence, I am an inveterate tinkerer. I like to experiment and I like to run things my way. (This is in contrast to my professional recommendations as a consultant, where I like conservative and tested.)

As such, despite having no problems with my previous host (Laughing Squid, which I still recommend), I decided to switch to a Virtual Private Server (VPS) so that I could have more flexibility and control over my server environment. I selected VM Storm based on a review of  “low-end” VPS providers (since this is my personal tinkering platform I don’t need to pay extra for a high-end name). I then added Nginx as my Web server, Varnish as a front-end cache, WordPress for blogging, and W3TC as a WordPress performance enhancer.

The Virtual Private Server

Remember that with a basic VPS, no one administers the system for you (unless you pay extra, of course). You need to make your own size estimates, then install and configure your Web server and everything else (the OS itself was installed by the provider). This, of course, is exactly what I was looking for, since I wanted to experiment.

While I probably could have made it work with an even more compact environment, I went with 512 MB of memory to give me some breathing room. I decided on Ubuntu 11.10 Server because I’m familiar and comfortable with Ubuntu, and because there are lots of online Ubuntu resources and help available.

The Web Server

I’m most familiar with Apache, a free, open-source, incredibly flexible and powerful Web server. But since I was interested in experimenting, I decided to try an alternative: Nginx(“engine x”), a fast and compact HTTP server that now powers sites like WordPress.comand CloudFlare. It’s known for its resource efficiency and speed, so it’s a perfect choice for smaller VPS setups (and it too is open source and free).

(Note: I thought about Lighttpd, another fast and compact Web server, but Nginx proved be easier for me to get going the way I liked.)

The Front-End Cache

Nginx is fast, but I wanted more. So I put Varnish in front of Nginx. What’s Varnish?

Varnish Cache is an open source, state of the art web application accelerator. You install it on your web server and it makes your website fly.

Basically, it’s a server-side caching proxy. It listens for HTTP requests, serves them really fast if they’re in its cache already, or forwards the request to Nginx if they’re not. Want to survive a Slashdotting? Use Varnish. (And then add CloudFlare for good measure!)

The Database

I went with MySQL (of course). It works. I added phpMyAdmin to help administer it, and put that behind Nginx running SSL with a self-signed certificate. I could have bought an SSL cert, but what’s the point? I know who I am, and no one else needs SSL access to my install anyway. (I’m not selling stuff through my site.)

The Software

While I could have experimented with other solutions for blogging, I wanted to stick withWordPress. It’s flexible, extensible, and nice to work with. It isn’t always the fastest or most optimized thing out there, but that’s what Nginx and Varnish are for!

WordPress was really designed for a LAMP environment: Linux, Apache, MySQL, and PHP. So replacing Apache with Nginx had the potential to create some challenges–which it did! But fortunately, Nginx is an increasingly popular choice, and one of the most powerful WordPress plugins out there (W3TC–W3 Total Cache) has added support for it, which made everything easier.

W3 Total Cache

W3TC is more than a cache. It bills itself as a “performance framework,” and although I often prefer the Unix “small-tool” philosophy, W3TC really shines. To be honest, it’s options for performance enhancements encouraged me to think about using a VPS in the first place, just so I could play with them. It handles disk and database or object caching (using memcache or PHP APC), content-delivery networks (like Amazon CloudFront), and even Varnish cache purging.

Resources and How-To Guides