Build Faster WordPress Sites with Nginx – In 3 Lines!

Apache vs nginx for WordPress

 

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.

NGINX Setup 1

Next we’ll need to select our image, this currently needs to be Ubuntu 12.04:

nginx-setup-2

Click create droplet and you’ll see your droplet spinning up in <60 seconds!

NGINX setup 3

You’ll shortly receive an email with the IP address and root password for your server. Open up your console and login through ssh:

NGINX setup 4

From here we can use rtCamp’s easyengine script, which will install everything required for us. To read more on the setup and options go here. To install easyengine paste in the command:

curl -sL rt.cx/ee | sudo bash

If everything goes  to plan you should see the following:

EasyEngine Install

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:

nginx-setup-6

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.

nginx-setup-7

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:

nginx WordPress installation

After a short wait while WordPress is downloaded and installed we’ll get our admin password shown ready to login.

WordPress Nginx

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.

nginx WordPress speed

  • Pingback: Weekly News Roundup No.7()

  • http://rtcamp.com/ Rahul Bansal

    This is Rahul from EasyEngine. This is so far best article on EasyEngine. Thanks for giving EasyEngine a try. :-)

    I just want to add a note about “Browser Cache – Disabled”. EasyEngine config has aggressive browser caching built-in. So W3 Total Cache’s Browser Cache settings are ignored.

    • GPLclub

      Hi Rahul,

      Thanks so much! EasyEngine is such a great script, definitely made our lives a lot easier. Hopefully more users get the chance to experiment with nginx.

      Sure, have also linked to your tutorials which obviously give more comprehensive info on EasyEngine.

      • http://rtcamp.com/ Rahul Bansal

        Glad to know that EasyEngine is helpful. :-)

        Tutorials are like “manual” version of EasyEngine. For most feature, we start with tutorials first. Then based on comments/feedback, as tutorials improve, we try to automate them as EasyEngine commands.

  • Pingback: Menjalankan WordPress Multisitus dari Apache (cPanel) Beralih ke Nginx — matriphe!()

  • http://www.cindysbeentrippin.com/ cindysbeentrippin

    Nice article, I’m going to have to give it a shot. Thanks Rahul and GPLclub.

    • http://rtcamp.com/ Rahul Bansal

      @cindysbeentrippin:disqus glad to know you found EasyEngine useful :-)

  • http://www.cindysbeentrippin.com/ cindysbeentrippin

    Also, any suggestions for getting my current WordPress setup to work with Nginx?

    • GPLclub

      Hey, are you looking to move to nginx? If you’re on Apache rtCamp have a number of tutorials for moving over, eg: https://rtcamp.com/tutorials/wordpress/migration-with-zero-downtime/

      • http://www.cindysbeentrippin.com/ cindysbeentrippin

        Thanks, I’ll try to check it out. I’m currently using a free control panel to run my hosting setup. I can easily switch it from Apache to Nginx but the WordPress pages end up 404. If I’m correct Nginx doesn’t use .htaccess so some modifications to WordPress have to be made? Also how does this play out with WordPress updates etc.? I looked into this for a bit at one time but then I got too busy doing other things.Thanks very much!

        • GPLclub

          Yep, nginx dosen’t support .htaccess at all so if you’re relying on redirects etc in your .htaccess file you’ll need to rewrite them for nginx. There are some resources for this available her: http://www.nginxtips.com/converting-htaccess-to-nginx/

          WordPress updates will happen just as normal, nothing different in that regard.

  • Pingback: Jon Brown Designs : Improve webpage speed with Digital Ocean()

  • Pingback: We Are Mac Gurus – Improve webpage speed with Digital Ocean()