How I migrated my WordPress blog to Digital Ocean in about 6 steps

Posted by:

Getting away from my old shared hosting provider was a necessity for me. I planned to write an important post, but my blog was reacting extremely slowly or simply failed to be accessible entirely. That was not acceptable! Since I had some experiences with migrating WordPress blogs and also some experiences with setting up a virtual private server / VPS / droplet on Digital Ocean, I decided to move my Radivis.com blog to a Digital Ocean droplet while keeping everything on the same domain.

In the following, I list up all the steps that I have taken to get to that goal. Ideally, if you want to copy that process, you should leave out the mistakes and hopefully “step 0” and “step ugh”. This is not a complete guide for the process of migrating a blog to Digital Ocean or just setting up a Digital Ocean droplet, but I hope you can profit from my experiences.

Step 0: Having no idea how to migrate exactly

As I mentioned, I have already migrated WordPress blogs a couple of times, but those were all regular migrations in which the URL of the blog changes. A migration in which the URL (in this case https://radivis.com) should stay fixed is a bit more tricky. Also, the step from shared hosting to an unmanaged VPS comes with some additional effort.
After some thinking, I assumed that I just had to copy all my blog data one to one to the new Digital Ocean droplet and then switch the DNS settings to the IP of that droplet. In principle, that’s mostly right, but the journey towards that goal comes with many pitfalls.

Step 1: Setting up a new droplet on Digital Ocean

The cool thing about Digital Ocean is that there are lots of how-to pages that explain everything in great detail to novices. In any case, several steps are required:

Step 1A: Registration and payment

Of course, you first need to register on Digital Ocean to start anything. If you want to save some money, you can use my referral code to get a couple of bucks for free on your Digital Ocean account: https://www.digitalocean.com/?refcode=f2559dd4e6b4
In any case, you need to set up a payment option. Digital Ocean accepts Paypal or credit cards, but unfortunately no virtual pre-paid credits cards like the one I regularly use for online purchases. If you have transferred a modest amount of money to Digital Ocean your account becomes activated and you are free to go.

Step 1B: Choosing the droplet options and create a droplet

By clicking on the big button “Create Droplet” in the top right on the Digital Ocean user interface you get to the droplet creation menu. There are many options available for your droplet, so let’s consider them one by one:

Droplet Hostname

There is a system to droplet names that should be used. The name should have the form function.domain.tld, where “domain” is the domain on which you want to place your WordPress blog, and “tld” is its top level domain, simple examples for “domain.tld” would be “example.com” or “something.net”. The “function” part of the name is the interesting one: It should indicate what the droplet does. Because you want to host a WordPress blog fitting function names might be “wordpress”, “wp”, or “blog”. If you want to keep an open mind and consider doing more than hosting a blog with your droplet, you can stick to a generic name and call it “droplet1” for example. What’s great about a VPS is that you can run any kind of web application on it, even those which are not supported by shared hosting providers. Here a some examples of some free and open source apps you could want to install on your droplet (of course, this is not an exhaustive list):

Detour: What free and open source software you can install on a Digital Ocean droplet
Droplet Size

For a small blog the cheapest $5 droplet with 512 MB RAM and 20 GB SSD space should suffice. Most small, medium, or even blogs can be run a $5 droplet with a sufficiently optimized setup. If you don’t want to delve into optimizing your software configurations or don’t care too much about money you can also take a more expensive droplet to be on the safe side.

Droplet Region

Digital Ocean has been expanding its choices for server locations. The London and Frankfurt locations are relatively new. It’s not like the exact choice of the server location plays a huge role, but you might be more comfortable with a server that lies physically close to your own location. Choosing a newer location may provide some advantages, because they are less crowded than the older ones, and because they may use more recent hard- and software.

Available Settings

You don’t really need any of this. IPv6 is nice, but it’s not a strict requirement at the moment. Backups are a good idea, if you do a lot of different things with your droplet, otherwise they are optional. The other options are only useful in rather special cases.

Droplet Image

CentOS, Ubuntu and Debian are popular solutions. CentOS is the OS that’s most widely used in the VPS ecosystem and if you want to be able to run any serious VPS software, this should be your choice. Otherwise, Ubuntu and Debian (my personal choice) are more convenient, and essentially equivalent, choices. Of course, you could take something else, but then you might have to deal with the problem that there’s not as much documentation and how-to support for the less popular operating systems.

For each OS you can select a version. Choosing the most recent version is generally a good idea, unless the software you use requires an older version. The choice between 32 bit and 64 bit systems is an annoying one. Technically, 32 bit systems may have a slight performance advantage over 64 bit systems for small droplets, but in practice it probably won’t matter a lot. Choosing a 64 bit system in any case might be a good idea if you want to scale your droplet up later on without having to think about the bit issue.

When you click on the “applications” tab you have the option to directly install a WordPress blog on the droplet. If you want a quick out of the box solution, then go for it. If you want to do everything manually, don’t select any applications. A medium route to take would be to select a LAMP stack (pretty much standard) or a LEMP stack (higher performance, but less standard) as pre-installed application. Then you would only have to install WordPress manually. Personally, I feel a bit uncomfortable about one-click installers and think installing applications manually is a more robust approach.

Add SSH Keys

This is the final option, but it’s not necessary to actually use it immediately. It’s totally legitimate to set up SSH keys later on manually – which I find actually more convenient than using the form on the Digital Ocean page.

Step 1C: Basic droplet setup

If you went through the process above, the really difficult part for VPS novices starts. Now you basically have your own server on the internet and have to learn how to manage it on your own! This is where the large amount of documentation that’s provided by Digital Ocean comes in really handy. There’s an almost unlimited amount of things you can learn, but at least you should learn about the following basics (there are many how-tos for each of those, I just selected those that I found most useful):

All of this may seem to be daunting at first, but learning about it is the price you need to pay for having an affordable but awesome virtual private server that is significantly faster and more flexible than shared hosting providers.

Anyway, here’s my minimal Debian 7 droplet basics:

Debian 7 basics

I’m personally using Kubuntu, a variant of the popular Ubuntu Linux distribution. For connecting to the server I use the Yakuake terminal program, because it’s much more convenient to use than the normal console windows.

First of all, I need to manage different droplets, and I have different SSH keys for each of them. So, on my own computer I first create an SSH key pair with the following command:
ssh-keygen -t rsa -f ~/.ssh/id_droplet_name -C “comment”
Here, “droplet_name” is the name of my droplet (with underscores instead of dots). I do use a passphrase for marginal additional security. Then I log onto the new droplet via

ssh root@droplet_ip

and change the root password. Next, I open another terminal window and type

ssh-copy-id -i ~/.ssh/id_droplet_name root@droplet_ip

to copy the public SSH key onto my new droplet. So, now I can log into my droplet as root via my SSH keys (plus my passphrase).

Next, some maintenance and setup steps are in order:

dpkg-reconfigure locales
opens a menu that lets me set up the language/locale of the droplet. Note: Selecting options works with the space key. With
dpkg-reconfigure tzdata
I can then select the correct time zone for the droplet. Then I type

apt-get update
apt-get dist-upgrade
apt-get install unattended-upgrades
dpkg-reconfigure unattended-upgrades

to update the droplet software and keep it updated automatically. Finally I set up a swap file. With all of that I have a droplet with a minimal basic setup. Now the really interesting stuff can start.

Step 2: Installing a control panel on my new droplet

I already installed a Vesta Control Panel earlier, so I knew how to do that. The problem is just that it didn’t work this time. When I tried to install it, there would be a pretty defeating error message. Only after looking up the VestaCP Homepage it dawned to me that Debian 7 was supported, but not yet Debian 8 which is the latest version of Debian that was just released a couple of weeks earlier. So, I deleted my droplet and made a new one with Debian 7. And that worked just fine. The installation is really simple:

curl -O http://vestacp.com/pub/vst-install.sh
bash vst-install.sh --force

The “–force” part is necessary, because VestaCP doesn’t like that the exim mail server is already pre-installed on Digital Ocean droplets.

After the installation I had to go to the URL https://droplet_ip:8083 to login as admin. Then I set up

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

as name servers. For the other DNS settings I use the Digital Ocean site directly instead of VestaCP. Finally, I created a new database for WordPress in VestaCP.

The main reasons why I chose VestaCP are:

  • It’s free
  • It is lightweight
  • It comes with both Apache and Nginx at once, which should ideally bring the best of both web servers

Step ugh: First migration attempt crashing and burning

Now here’s how I went about my first migration attempt: First I made a backup of my blog with the UpdraftPlus plugin. It’s a really good plugin and restoring backups usually works fine. So, I thought I could just import a backup in a new WordPress installation on my new droplet and everything might just work. Well, it didn’t. After I installed WordPress manually on the new droplet I also installed UpdraftPlus, copied the backup I made earlier into the UpdraftPlus folder on the new droplet and restored the backup. UpdraftPlus actually warned me about the URL of the blog being different (the URL of the fresh WordPress installation was just the IP address of the droplet, but I ignored that warning.

Afterwards the site didn’t work. Actually, what it did was direct me to the original blog on radivis.com. So, what I did was to change the name server settings on my old host to the digitalocean name servers above. The Digital Ocean name servers would then resolve radivis.com to the IP of my droplet. Then I waited in the hope that the internet would accept the name server change and direct radivis.com to my new droplet. When it did, the site was gone. I checked that I had the correct new settings for the database in the wp-config.php file. Yes, they were correct, but when I checked out the /wp-admin page I was greeted by a page that told me these changes were somehow not really accepted, because the site looked for the database at the old database path.

Furstrated, I went ahead to delete my WordPress installation on my new droplet and reverted the name server changes. Radivis.com would then be resolved to my old shared hosting provider.

Step 3: Trying several migration plugins

This failure made me realize that I better should have used a proper migration tool. So, I tried out the migration tools that I have already worked with and which proved to be really useful:

  1. Duplicator: Probably the best migration plugin for WordPress. Unfortunately this didn’t work, because my shared host didn’t have the right file compression package installed or something.
  2. All-in-One WP Migration: Probably the second best migration plugin for WordPress. This time it almost worked. But the export of my database never finished, even though it wasn’t especially big.
  3. WP Migrate DB: This plugin just migrates the database. When using Migrate DB, I also changed the local installation path of WordPress. Apparently the paths of my old shared host and the new droplet were completely different. This is something that I haven’t considered when simply trying to import a database backup! But with Migrate DB the process worked fine. Unfortunately, the normal version of Migrate DB can only export the WordPress database. The import has to be done manually.

So, on the new droplet I installed a WordPress freshly again. Then I copied the regular files with SFTP to the new droplet. Importing the WordPress database was slightly difficult. VestaCP comes with phpMyAdmin and you can import databases with that tool, but the default Apache settings didn’t allow me to actually do that, because by default you can’t upload files larger than 2MB (upload_max_filesize = 2M). So, I had to edit the php.ini file that Apache uses (which I found with the command locate php.ini)to increase that limit, and also increased post_max_size from 8M to 50M. With these settings I could successfully import the database file.

In retrospect, this was a too complicated method for importing a database. It’s much easier to do that over the command line! Anyway, I reverted the php.ini settings to their default values afterwards.

Interestingly, after the import of the database the site showed me a white screen of death. In the hope that changing the name server settings to those of Digital Ocean again would fix the problem, I did just that.

Step 4: Fixing the white screen of death

Nope, the site was still broken after radivis.com pointed to the IP of my droplet. So, I googled what to do against the white screen of death of WordPress. The first proposed solution was temporarily renaming the plugins folder, so that all plugins would be deactivated. That actually fixed the problem immediately.

Step 5: Cleaning up

With the migration completed I wanted to improve the performance of the site. First of all, I installed the P3 plugin which measures how much plugins impact the performance of WordPress. The results were scary, so I deactivated or deleted some plugins that were unreasonably resource greedy.

Afterwards I still had to deal with a memory issue. Apache seems to be terribly hungry for memory, so I had to adjust its settings according to this guide to moderate its memory use.

In the future I might use another guide to set up the Varnish caching engine to reduce the load for Apache even much further.

Edit (2017-08-13): For some more information on hosting providers in general, check out Cheap Web Hosting Guide: 19 Secrets Nobody on The Payroll Will Tell You on Cloudwards. Note that Digital Ocean still stands out as seriously affordable VPS provider.

4

Comments

  1. James Scott  April 4, 2016

    Nice story, very well written tutorial. Digitalocean service and cost is the best. I migrated my WordPress blog to Digitalocean learning from here. http://www.cloudways.com/blog/host-wordpress-on-digitalocean/

    reply
  2. Aaslin  December 4, 2016

    Thanks, Trying to migrate a couple of sites to digital ocean & your post helped a lot.

    reply
  3. Afrielect  March 11, 2017

    Thanks for sharing these step by step instruction, I will follow your instruction to migrate my blog.

    reply
  4. Afrielect  March 11, 2017

    I am considering to move http://orjiakor.com to another host.

    reply

Add a Comment