I’ve had a number of tiny WordPress sites on shared hosting (BlueHost) for over a decade. It’s been pretty great. Shared hosting has a lot of benefits: it’s cheap, it’s relatively easy to manage, e-mail is included, and there’s basic support.
The drawback is that servers aren’t generally optimized for WordPress performance, and once a site begins to scale in traffic you need to move it to a managed host or a VPS.
I’ve been wanting to try DigitalOcean (one of the many cloud providers) because my hosting bills have been growing. I still have my basic shared hosting with BlueHost, but I also have large sites on WP Engine, and a VPS with WiredTree. They’ve all been great and have their own benefits, but the idea of consolidating into one provider and reducing my hosting bill significantly is a huge draw.
The big hurdle with cloud hosting for most people is that there are no easy control panels to log into and there’s no support tech available on chat. You also need to be at least somewhat comfortable on the command line.
To hopefully make it a bit easier, I’m sharing the steps I used to set up and migrate multiple sites to the same Droplet.
If you just need one site, it might be simpler to have DigitalOcean set up WordPress (under Applications) when you create the Droplet, and then skip to the migration steps.
a) Create an account with DigitalOcean.
b) Click “SSH Keys” and add your public key.
Cheatsheet: To copy your public key, open terminal and enter:
pbcopy < ~/.ssh/id_rsa.pub
That should save it to the clipboard, which you can then paste in the field for DigitalOcean.
GitHub has a good instructions for generating an SSH key if you don't have one.
c) Click "Create" to build a new Droplet.
- Give the Droplet a name you'll remember.
- Choose a size (I went with the smallest to house my low traffic sites).
- Choose location and server, I went with the defaults (New York, Ubuntu 14.04 x64 server).
- Add your SSH key.
- Click "Create Droplet".
Your droplet will take few seconds to set up. When it finishes the IP address will be at the top of the dashboard. Go ahead and copy this. Throughout this tutorial I'll refer to that IP address as xxx.xxx.xx.xxx.
Next step is to SSH into your new Droplet. You need to use the root user to do this. Open terminal:
(You shouldn’t need a password if your SSH key was added correctly)
To set up the WordPress site(s), I used a script called EasyEngine. You can read the full documentation.
To install EasyEngine, run this from your Droplet:
wget -qO ee rt.cx/ee && sudo bash ee ee stack install
For this tutorial, I'm going to use "example.com" as the domain we're setting up. Just replace this with your own.
If Easy Engine prompts you with "Enter hostname [FQDN]:", go and enter the domain name ("example.com").
To install WordPress (including the database set up) run:
ee site create example.com --wp
(There's also other options listed in the EasyEngine docs you can check out.)
Once EasyEngine sets up the site, copy down the username / password it creates if you are setting up a new site and need access to it. If you're migrating a site (as I am), then this isn't important as the database will get overwritten.
EasyEngine installs sites in the "/var/www/" directory. If you want to view those files, go:
View the Site
To view the new WordPress site on the Droplet, you'll want to update the hosts file on your local machine. Leave the remote shell and open a new terminal tab on your local machine. To edit the hosts file:
You'll want to add a new entry to the bottom of the hosts file that has the new IP and the domain name you wish to point:
When finished, save out the hosts file.
At this point, let's also clear cached DNS so we can make sure we're viewing the right site.
From terminal run:
sudo killall -HUP mDNSResponder
Then open Chrome (I'm just assume you use Chrome), and go to this url: chrome://net-internals/#dns. Click the "Clear Host Cache" button.
Now, if you migrate to example.com you should see a fresh install of WordPress. Perfect!
Migrate a Site
There are many different approaches you could take to migrating a site. I've been using WP DB Migrate Pro(affiliate) as it's dead simple to set up and I don't need to SSH into multiple servers.
But doing it manually is not too rough. For the purposes of this tutorial, I am going to assume you have the "wp-content" directory for the site you wish to migrate and an export file of the mySQL database ("database.sql") saved on your local desktop (though the steps aren't too much different even if you are ssh'd into a different remote server).
First we'll want to compress the "wp-content" directory:
tar -czf wp-content.tar.gz wp-content/
Now, transfer that to the remote directory where the new WordPress install is:
scp wp-content.tar.gz email@example.com:/var/www/example.com/htdocs
(Depending on the size of the file, this might take quite a while to transfer.)
Let's also get the database export uploaded, we'll put this in the root of the new site though:
scp database.sql firstname.lastname@example.org:/var/www/example.com/
Now, switch back to the remote shell and make sure you're in the files directory for the site (/var/www/example.com/htdocs). We're going to remove the current "wp-content" directory, unzip the new one we uploaded, and then remove that zip file:
rm -rf wp-content gunzip -c wp-content.tar.gz | tar xopf - rm wp-content.tar.gz
Next is the database. Let's grab the database credentials that were set up by Easy Engine.
Navigate to the root of the new site directory (/var/www/example.com/) and open the wp-config.php file:
Copy down the database_name, username and password.
We've already uploaded the database export to this directory, so now let's overwrite the current database (replace username and database_name with your own of course):
mysql -p -u username database_name < database.sql
Check in the browser to see if your site loads at example.com. If so, we can now remove that database file:
Everything is good right? The site is up, looking nice. Great, one more step.
Remember we set our hosts file locally to point to the new IP address? Let's remove that now and flush the DNS again. This should get us pointed back to the original site. (I'm not going over the steps again, just hop back up to that point in the tutorial and follow it in reverse).
In the DigitalOcean control panel, click "DNS" and then "Add Domain". You'll want to add the domain name for the new site and select the Droplet it points to.
Now you're ready to point the nameservers for the actual domain to DigitalOcean. You'll need to find where your domain is hosted, log into that control panel, and point the nameservers to:
ns1.digitalocean.com ns2.digitalocean.com ns3.digitalocean.com
Those steps are described in more detail here in the DigitalOcean docs.
Hopefully this has been helpful. It took a few hours of extensive Googling and a lot of trial and error for me to piece together all the steps. If you have any additional suggestions or tips, feel free to leave them in the comments.
If you haven't had enough, I also posted some additional tricks and shortcuts for syncing files.
If you're not sure how to edit or view your databased without PHPMyAdmin, I found a tool for OSX called Sequel Pro which is free and worked pretty well.
Server Pilot was also recommended to me by a few folks. It provides a control panel and some other features which make it easier to deploy to cloud providers.