How To: Install the fastest server stack for WordPress on Digital Ocean using Server Pilot in less than 30 minutes

Here’s what you will get by following this guide:

  • The Server Pilot interface to manage your server
  • A really fast server using the latest tech to make your WordPress site as fast as possible
  • A real CRON job to process your imports/backups more quickly and efficiently
  • Free SSL certificate
  • Very low monthly cost – e.g. $5pcm per server
  • Your current site migrated to this new server on a dev domain
  • Instructions to flip the switch and make your dev site live when you’re convinced of the performance gains

If you’ve been following me a while, you’ll know I offer a fork of the Mercury stack. When it comes to server-side performance of your WordPress site, here are the default elements you get with most hosts:

  1. Apache – serves images, css, javascript and other static files and processes PHP
  2. PHP 5.6 – processes the PHP instructions in the WordPress core and all the plugin files, interacts with your MySQL database and constructs HTML to be passed to Apache
  3. MySQL 5.6 – stores your data, options, posts, products, users, settings amongst other things. Takes commands from PHP and tries its best to serve up the results as quickly as it can.

The WPI Fast WordPresss stack (Mercury fork) on the other hand has this:

  1. Cloudflare – serves static files (images, css, javascript) from free CDN locations around the world
  2. Nginx – instead of Apache – lighter, faster, less memory, scales better, responds quicker
  3. Fail2ban – bans IP addresses for a day when bots try to hack your site – bots can *hammer* your site with thousands of hits per minute, so this really helps performance
  4. PHP 7 – about 3 – 5 times faster at processing most PHP code compared to 5.6
  5. PerconaDB – almost twice as fast as MySQL 5.6, and doesn’t suffer dips in performance like MySQL does when it does its garbage cleanup

There used to be some extras in there – like Varnish in front of Nginx, Memcached behind it – but these have since been removed. Varnish because Cloudflare is really doing its job for it, Memcached because PHP 7 is not yet fully compatible.

A quick technical side-note about Nginx, fail2ban and Cloudflare

There are some elements which are difficult to notice – like Nginx was rebuilt to include the originator IP so that fail2ban can work properly. Fail2ban will ban IP addresses based on certain patterns of activity – failing to log in 5 times, hitting xmlrpc.php multiple times etc. If you’re using Cloudflare, the IP address as far as Nginx is concerned is the Cloudflare IP address. Without the rebuild, that means you end up banning every user who comes to your website from that part of the world using that Cloudflare IP. With the nginx rebuilt, you get the original users IP address passed through properly so fail2ban can ban the correct IP address.

A quick technical side-note about MySQL and PerconaDB

Most hosts will give you MySQL 5.5 or MySQL 5.6. 5.5 came out in 2010, 5.6 came out in 2013 and 5.7 came out in 2015. While they may sound like minor revisions, they are major. 5.5 does not support fulltext indexes if you are using the InnoDB database structure. The InnoDB database structure is what you should be using as it’s faster than MyISAM (the other option). These are storage engines, like having a filing cabinet versus having a pile of papers on your desk.

5.6 and 5.7 also include major performance enhancements over the previous versions, so you really want the latest version. But the story doesn’t end there. MySQL has two main forks – versions made by other people/companies which have different features yet are 100% compatible with the original. These forks are Maria DB and Percona DB. Both are almost twice as fast as MySQL.

I prefer Percona DB for the query analysis toolkit provided – you can get a league table of which queries are hitting the server the hardest over time.

The problem with my Mercury fork

I’ve built a few of these installs for people and unfortunately I’ve had to keep the price quite high – it takes me time and it costs a lot in support too. I’m on a mission to make WordPress the fastest platform on the planet so this is far from ideal. I did make a DIY guide so users can install it themselves, which a lot of people used, but it was complicated – too complicated for many.

I tried going with the Ajenti interface to simplify things for people, but that wasn’t really perfect either – and there’s still the problem of the builds taking my time. I’ve semi-automated a lot of this – built snapshots to a certain level where I can then run fewer commands to get users up and running, but it still takes my time. To scale this, it needs to take none of my time yet still bring you all the performance benefits.

Server Pilot to the rescue

A client of mine brought Server Pilot to my attention. What Server Pilot does is make it *easy* to install WordPress onto Digital Ocean. What the rest of this article will show you, is how to do that and then upgrade your server so you get most of the Mercury stack and a really fast server for very little money with a great interface to manage it.

Server Pilot will be free for most of you (they give you 1 user account free, they charge for extra when your business grows), and $5pcm Digital Ocean droplets will suffice for most of you – see the table below for a guide to droplet choice.

I *love* Digital Ocean – the speed of the servers they provide, the interface, the pricing, the speed of creating a new server, the snapshots, the location choices – everything about them is great.

Now with Server Pilot adding PHP 7 support, you can get blazingly fast speeds for next to nothing and you can do it yourself!

How Server Pilot Works

Create a new droplet, then give the IP address and root password to Server Pilot (see guide below for extra security on this) and it will set up and install your WordPress website for you. Choose PHP 7 in the interface, add a free Cloudflare in front and upgrade your database to Percona DB or Maria DB and you will be seriously flying.

Here’s the stack Server Pilot uses:

  1. Nginx
  2. Apache
  3. PHP (5.5, 5.6, 7.0 or 7.1)
  4. MySQL 5.7 (5.7 is good – better than 5.6 which is way better than 5.5)

You’ll notice Apache in there as well as Nginx. They are using Nginx to process web requests, serve static files etc, then pass through the PHP requests to Apache. This alleviates the majority of the performance problems Apache suffers from due to its architecture and is a nice elegant solution.

They also offer PHP 7 which is 3-5 times faster at processing PHP code. And they give you the latest version of MySQL – 5.7. So it will be far faster than your normal hosting.

All that remains is to add Cloudflare in front and configure THAT to do what fail2ban would otherwise do, and then upgrade your MySQL installation to Percona DB.

Step by Step Guide to Migrating to Server Pilot + Digital Ocean

This guide will take you through, step by step, migrating your existing WordPress site over to Server Pilot with a new temporary domain so you can test out the performance gains.

You can also follow this guide to create a brand new WordPress site – there are steps you can skip if you are not migrating and these are noted throughout the guide.

For the purposes of this guide, I will migrate https://www.wpintense.com over to https://dev.wpintense.com.

At the end of the guide, I’ll show you how to swap your dev site to live once you’re convinced of your new found performance gains and you’re ready to flip the switch.

1) Create a Digital Ocean Droplet

create-droplet-digital-ocean

If you don’t already have a Digital Ocean account, sign up through this affiliate link to get $10 credit (2 months free!)

Click the button to create a droplet and then:

Choose Ubunutu 16.04 – this gets you the latest of everything

The size you choose depends on database size, traffic volume and import activity. Here are some rough examples based just on database size and import activity (Datafeedr or WP All Import). Choose larger if you have high user traffic.

  • $5pcm droplet – can handle 20,000 products/posts
  • $10pcm droplet – can handle 100,000 products/posts
  • $20pcm droplet – can handle 500,000 products/posts
  • $40pcm droplet – can handle 2 million products/posts
  • $80pcm droplet – you get the idea.

At any point, you can click a button to have your droplet upgraded within a few minutes. So start out with the smallest you need and you will be very surprised at the performance results you get.

Choose whichever location you wish – the closer to your customers the better.

Choose backups if you wish, although you can use UpdraftPlus if you like with off-site backups.

Choose a name – e.g. serverpilot-wpintense is what I called mine.

Don’t bother with the SSH keys since Server Pilot uses username + password.

Click Create. You will be emailed the root password.

2) Create a secure root password

Digital Ocean will have emailed your root password to you. Your server’s root password gives 100% total access to your server to do whatever you like with it. You don’t want it falling into the wrong hands.

You can skip this step if you don’t mind sleepless nights, but if like me you worry about the fact your email gets *everywhere* – onto every device you own, your PC, your laptops, your tablets, your phones – then you’ll realise your server is not secure until you create your own root password that doesn’t exist in your email history.

access-console

Here’s how:

  1. On the page after your droplet has been created, click the More button then Access Console.
  2. Now enter the username: root then the password that was emailed to by Digital Ocean. You will have to type it twice.
  3. Then it will ask you for your new root password. You will have to type this twice.

Note: Nothing appears on the screen as you’re typing the password – no stars, nothing – and you can’t copy/paste using the Digital Ocean console. Advanced users can connect using Putty instead and that way you can right click the Putty screen to paste your old and new passwords.

3) Connect Server Pilot to your server

If you don’t yet have a Server Pilot account, create one through my affiliate link here: https://www.serverpilot.io/?refcode=dd41ab931d8a – it will get you $10 credit. You probably won’t need to ever use this however, since most of you will just need the free plan.

Once you are logged in, click the big massive Connect Server button in the top right.

connect-server

You will have 3 fields to complete:

  1. IP Address – copy/paste the IP address from the email sent to you by Digital Ocean
  2. Root password – enter the root password you configured in the previous step, or the original Digital Ocean provided root password if you are living dangerously and skipped Step 2
  3. SFTP password – enter another new password here. When/if you use Filezilla to connect to your server to view/edit your files, you will use this password.

serverpilot-config

4) Configure your DNS

We are going to make a temporary website – a development website – somewhere you can see the performance of your new server in action before you flip the switch to make it live.

So – visit your DNS provider (the place you bought your website URL) and add a new A Record to your domain. I will show you how to configure Cloudflare later in this guide, but to get you set up quickly, add the A record on your existing DNS provider.

The A record will have two values – the name and the IP address. The name is the subdomain you are going to use, so in this example ‘dev’ and the IP address you can copy/paste from your digital ocean email. So in my example, creating an A record for dev means dev.wpintense.com requests will go to this new server’s IP address.

If you are creating a *new* server instead of migrating, just edit your existing A records (there should be 2 of them) and change the IP addresses to those of your  new server.

set-up-a-record

5) Create your WordPress installation using Server Pilot

By the time you have configured your DNS, Server Pilot will have finished building your server. Head on back to that page and you will see this:

create-wordpress

Click that big Create App button then you’ll get a form to complete:

create-wordpress-app

  1. Name – it’s for display in Server Pilot, so I use wordpress
  2. Domain – enter your domain as if your server were live, even if migrating. e.g. don’t enter dev.wpintense.com, enter wpintense.com. This is so SSL certificates are created properly for your new server. We will add the dev domain as an additional step in a minute.
  3. Tick the WordPress box
  4. Enter a title – if you’re migrating from another hosting company then this doesn’t matter much as we’ll be overwriting the database with your backup from live
  5. User & password – enter a WordPress username and password – if you’re migrating from another host, these will be overwritten when you restore from your backup but to keep the Server Pilot interface working with your migrated site enter your current WP admin username and password.
  6. Choose PHP 7.0
  7. The remaining fields will be autoselected so click Create App

6) Add your dev domain

If you are migrating, add your temporary dev domain so you can copy from live to dev and test before you flip the switch.

Click the Domains tab and enter your dev domain, e.g. dev.wpintense.com and click Add

temporary-dev-domain

Here’s a note for how to connect to your new site using FileZilla to access your files

  • Download, install and open Filezilla
  • Click File menu -> Site Manager
  • Click New Site and type in a name, e.g. WPI Server Pilot
  • In the host box, enter the IP address for your new server
  • Choose SFTP in the protocol dropdown box
  • Choose logon type Normal
  • Enter username: serverpilot
  • Paste or type the SFTP password you configured earlier
  • Click Connect
  • Click OK to say you trust this host
  • You will be in the /srv/users/ folder – navigate to /srv/users/serverpilot/apps/wordpress/public (if you named your app wordpress earlier) – this is where all your site’s files exist and is the root of your domain

Migrating your site to the new server

You can log into your new server now. If you’re not migrating, you can skip the next steps.

I’ve outlined a three options below – many folks like the Duplicator plugin but I find it breaks like every time I use it, but then my databases are large. If you have a smaller database, the Duplicator plugin may be easier for you to use. I tried it for transferring www.wpintense.com to dev.wpintense.com but it broke again. I prefer Updraft plus because it just works every time. For larger sites, I use SSH.

Option 1) Migrating your site using UpdraftPlus

Create a backup of your live site

  1. Log into your live site
  2. Install UpdraftPlus
  3. Create a backup
  4. Download the backup files

Restore to your live site

  1. Log into your new dev site
  2. Install Updraft plus
  3. On the Existing Backups tab for Updraft Plus, click the link to Upload backup files and choose your backup files
  4. Refresh the page once it’s completed uploading
  5. Click to restore and tick everything to restore
  6. Because you have a different domain in use, it will warn you it’s a migration, not a restoration – just skip that – we will search/replace manually below to complete the migration

Option 2) Migrate with direct transfer of files to your new site using SSH

Your database files might be very large. Better to transfer them directly rather than down through your broadband and back up through your broadband. Here’s how:

Create a backup of your live site

  1. Log into your live site
  2. Install UpdraftPlus
  3. Create a backup

Transfer files directly

  1. SSH onto your new site (use putty to connect using your serverpilot username)
  2. Navigate to your updraft folder (e.g. cd /srv/users/serverpilot/apps/cartgrabber-wordpress/public/wp-content/updraft)
  3. Run: SFTP oldipaddress
  4. Confirm yes you trust it
  5. Navigate to the updraft folder – e.g. cd /var/www/html/yourdomain.com/wp-content/updraft. You can use following commands to help you figure out where you are: ls, cd
  6. Run: get backup*

The files will transfer directly – far more quickly than down to your computer then back up to your new server.

Restore to your live site

  1. Log into your new dev site
  2. Install Updraft plus
  3. On the Existing Backups tab click ‘rescan folder’ – this will find the backups you manually copied over
  4. Click to restore and tick everything to restore
  5. Because you have a different domain in use, it will warn you it’s a migration, not a restoration – just skip that – we will search/replace manually below to complete the migration

Option 3) For ultra-manual migration approach if UpdraftPlus ever doesn’t work, you can do:

  1. SSH to your old site, navigate to the webroot folder
  2. Run: zip -r backup.zip wp-content
  3. Run: mysqldump -u username -p dbname > backup.sql (then hit enter and then enter password)
  4. SSH to your new site
  5. SFTP oldipaddress
  6. Navigate to webroot
  7. Run: get backup*
  8. Extract these zip files to somewhere then copy the wp-content/* to your new wp-content folder
  9. Then replace the DB using: mysql -u username -p dbname < backup.sql

Note: The above approach presumes everything custom in your site is in wp-content. If it’s in /assets/ or somewhere instead, you’ll also need to copy those files over.

Search/Replace in your database to change all www.wpintense.com references to dev.wpintense.com

Now that your site is copied across, you need to replace everything in the database referring to the old domain name so we can test the new website first, before putting it live.

This is the only tricky part about using Updraft Plus and in fact if this is too tricky for you, you can go UpdraftPlus premium and it includes this functionality in the plugin.

  1. Download the Interconnectit search/replace script from here: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
  2. Extract the files, upload the folder to your /srv/users/serverpilot/apps/wordpress/public folder using Filezilla (see details for how to connect in Duplicator steps)
  3. Visit your sitedomain.com/searchfolder – e.g. http://dev.wpintense.com/searchreplace
  4. It will automatically pick up database credentials
  5. Enter www.yourdomain.com in the search box and dev.yourdomain.com in the replace box
  6. Hit Live run and wait

Now you can log into your dev site and see an exact replica of your live site, except it’s much faster.

How to make your site live

Once you are happy that the performance of your new hosts outperforms your old hosts, you can flip the switch. Here’s how to do it with zero downtime:

  1. Run the search replace script again by opening http://www.yourdomain.com/searchreplace
  2. Enter dev.yourdomain.com in the search box, www.yourdomain.com in the replace box
  3. Hit live run and wait
  4. Visit your DNS and edit the A records for www.yourdomain.com and yourdomain.com to point to your new IP address
  5. Once you have completed this final search replace and confirmed you are live, you should delete the searchreplace folder interconnectit script as it’s a major security hole leaving it there.

That’s it – you’re live!

I’ve got to catch a flight, but I will add the extra stuff to this page including:

  1. Configuring cloudflare
  2. Configuring real cron
  3. Upgrading to PerconaDB
  4. Additional performance steps you can take to optimise what server pilot give you out the box

But even without these extra steps, you’ll find that PHP 7, Ubuntu 16.04 and MySQL 5.7 give you major speed boosts compared to other hosts. You’ll get an extra 80ish% once you upgrade to Percona DB too for your database queries, and I’ll cover that ASAP right here in this guide.

 

 

Dave Hilditch
Talk to me

Dave Hilditch

Founder at WP Intense
Dave has been programming since 6 years old and has been developing WordPress plugins, themes and websites since 2010. In the past he built the fast browse view technology for Skyscanner and now he is on a mission to make WordPress the fastest platform on the planet.

He is always on at least one of his computers when he's awake, so get in touch and he'll get right back to you.
Dave Hilditch
Talk to me

Latest posts by Dave Hilditch (see all)