In our last post on optimizing your WordPress site speed, we discussed how easy it was to set up your own SSD powered VPS with Digital Ocean WordPress hosting and reap the speedy benefits. This time though we’ll take it a step further; the status quo for a WordPress supporting stack is Linux, Apache, MYSQL & PHP, or LAMP. However, dropping the Apache part of the stack can be a very attractive option; whilst Apache is well suited for handling WordPress sites, performance can often degrade under high loads, it is inefficient in serving up static content and can quickly consume precious resources.
There are a number of competing web servers but nginx is probably your best bet, conceived relatively recently in 2002 by Igor Sysoev, nginx was built from the ground up with the explicit goal of handling a large number of concurrent connections. In simple terms, whereas Apache creates a new process for each new connection (visitor/http request) nginx offloads requests to worker processes and allows for asynchronous resource allocation. What this means in practice is a much faster, more efficient server environment and in turn a faster website.
Sounds great, right. But how would you go about setting this up? Luckily, the nginx & WordPress experts over at rtcamp have build an awesome script for taking a stock Ubuntu VPS image, installing the required server components and a fresh WordPress install with pre-configured support for caching, in basically 3 system commands!
We’ll walk you through the process:
For maximum speed, ease of use and general hosting goodness we’ll be using a VPS from Digital Ocean, whilst this tutorial will be focusing on DO, there’s little to no difference in the actual server setup so feel free to use your preferred host.
Once you’ve signed up you’ll see an option to create a new droplet, clicking this you’ll be prompted to select your configuration. For the hostname, if you’re setting up a live site with a domain name you’ll want to use your FQDN such as “www.example.com”, we’re just testing so nginx will work for us. You’ll probably want to start with a small 512MB or 1GB droplet which should be more than enough for nginx + WordPress.
Next we’ll need to select our image, this currently needs to be Ubuntu 12.04:
Click create droplet and you’ll see your droplet spinning up in <60 seconds!
You’ll shortly receive an email with the IP address and root password for your server. Open up your console and login through ssh:
curl -sL rt.cx/ee | sudo bash
If everything goes to plan you should see the following:
Next we can install the dependencies; nginx, php, mysql and postfix. Paste in the command :
ee system install
After a short wait, you’ll be prompted with the following:
If you don’t have a static IP (if you don’t know, then you probably don’t) then you can leave this blank. Next enter a username and password for remote authentication to the protected /ee area.
After this you should see the completion message telling you can now create your WP site.
Now we’re ready to install WordPress, but we have a few options at this point. We’re going to use the “ee site create” command with a couple of arguments. Easyengine can create a multitude of different sites, including basic HTML, PHP and WP sites, but also MultiSite WordPress in a number of different configurations. For a full list of the possible sites easyengine can create read this document. This time though, we’ll stick with a simple WordPress install with W3 Total Cache preinstalled and configured. To get this we’ll need to paste in the command, making sure to change example.com to your site name:
ee site create example.com --wp --w3tc
In our case, we’re not using a domain so we’ll use our IP address instead:
After a short wait while WordPress is downloaded and installed we’ll get our admin password shown ready to login.
As shown, you’ll be prompted to update your permalink and w3tc chache settings, but at this point we’ve got a functioning WordPress site running on a super fast nginx powered server!
rtcamp recommends specific settings for W3, which are:
- Page Cache – Disk Enhanced
- Minify – Disable this unless you are 100% sure your theme/plugin will support it nicely.
- Database Cache – Memcache
- Object Cache – Memcache
- Browser Cache – Disabled
- CDN – You can use any CDN. Origin Pull is recommended.
Testing our basic site at popular site speed calculator, pingdom we can see that it performs very well. This speed benefit will really come into it’s own at higher loads though.