Linode, Nginx and WordPress, Sitting In A Tree

Last weekend, spurred on by a geeky Saturday spent revising Computer Science with @Rice, I decided to take the plunge and set-up a VPS with Linode. It’s been a fun and interesting experience and one I thought would be worth sharing.

I’ve been with my current host Dreamhost for nearly 5 years now (wow, can’t believe it’s been that long!) but have never truly been happy with the service. When I first started toying around with websites I followed the usual mentality of looking for the highest numbers with the cheapest cost. Combine that with some ridiculous offers ($97 referrals!) and hosting a lot of sites for friends and families means my shared account on Dreamhost has served me well. The service from Dreamhost can only be described as utilitarian. You get what you pay for and not a fat loss else. Massive overselling is offset by the fact that my server load is rarely below 5.0 and can often be as high as 20 or more.

Now that I’m professionally working in the web arena though it was high time to buck up my ideas and start putting down money on a “proper” host. There are other shared hosting providers such as WebFaction, but I wanted to go the whole hog, to get my own machine (even if it is a virtual box). After asking on Twitter and shopping around it seems Linode pretty much beat all of the competition from the likes of Rackspace and Slicehost.

As with most first-trials I went with the most basic option provided by Linode, the 360 box at $20 a month. It should be more than sufficient for what I need and Linode make it painless to upgrade later on. I’d also been itching to try out an alternative to Apache called Nginx (pronounced Engine-x). It’s a web server, much like Apache, but it’s designed to be much more efficient. I didn’t fancy the task of compiling it myself but luckily Linode provide “StackScripts” automatic distributions that set up an entire environment for you. And because you can view the scripts behind them, updating later on is a cinch.

A few hours later I had an Ubuntu Server distro up and running with Nginx serving HTML pages. PHP was a bit trickier however. Within Apache, mod_php handles all of the dynamic processing a PHP page typically required. This means each request loads up the entire PHP environment. That means a lot of memory wasted when just serving static files.

A lot of guides online will recommend using SpawnFCGI with Nginx to get your PHP scripts up and running but this is bad for a few reasons that I won’t go into here, feel free to Google it. The best solution I’ve found so far is PHP-FPM. This is set to be baked into the main PHP release in a future version, but for now it means a custom make job, again taken care of by the StackScript on Linode.

Linux, Nginx, PHP, MySQL, all that was left is WordPress. The famous five-minute install was just that, drop-dead simple. The only difficulty is in the permalinks. As WordPress checks only for mod_rewrite you will get horrible index.php/page/slug URLs. A quick tweak to my nginx.conf for this server and a brilliantly simple nginx-compatability plugin for WordPress to overwrite the mod_rewrite check mean I have beautifully clean URLs once more.

And now onto the numbers. I’m a geek and part of that means benchmarking. Of course all benchmarks are subjective but at the end of the day, I just want to know if I’m getting what I’ve paid for. Good ole’ Apache Bench was my weapon of choice, making a 1,000 requests with 10 concurrents to a default WordPress install on both my Dreamhost and Linode accounts. The numbers should speak for themselves.

Dreamhost: 8.57 req/s

Linode: 48.1 req/s

That’s a bit of a difference. Add in some memcaching and it’ll hopefully get even better. I’ve got to post my Nginx and PHP(-FPM) configs online at some point for @jaspertandy but almost all of it has been copied from ServerFault.

So, in a word, Linode is amazing. The ability to keep a few images around, boot up and play around is great. And having an SSH window open is a guarantee to make those glancing at your screen wonder what you’re up to. Heck, I might even change my hostname to CIA just for laughs.