How to migrate a WordPress blog from one droplet to another existing droplet?

July 8, 2017 146 views
WordPress Backups Ubuntu 16.04

I have two droplets, D1 & D2. D1 has one wordpress blog hosted on it while D2 has 3 blogs hosted on it. Both D1 & D2 have LEMP stack. I want to move the blog hosted on D1 to D2. Could someone please tell me how to go about it? I am pretty new to Digital Ocean and Linux.

2 Answers
hansen July 8, 2017
Accepted Answer

Hi @anshuldixit

Since I don't know how much you know or tools you have available, I'll try to list most.

First, you need to stop using (meaning updating/editing D1's WP).
Then I would highly recommend that you take a snapshot of both D1 and D2 via the DigitalOcean control panel, so you can revert completely in case of total failure.

Then let's take a backup of the WordPress database of D1. If you have phpMyAdmin, then use that, otherwise I would recommend that you use

Login to D1 via SSH. I'm guessing you have setup both servers with password and not keys, if you are using keys, then let me know.
Now let's copy all files from D1 to D2, but since I don't know your exact web-root paths, you will need to adjust those. I'm expecting that D1's web-root is /var/www/html:

scp -pr /var/www/html root@THE-IP-OF-D2:/var/www/DOMAIN-NAME-OF-D1-WEBSITE
# Example
# scp -pr /var/www/html root@

It's going to take a little time to copy the data depending on how many media files you've uploaded to D1's WordPress.

We will copy the Nginx configuration as well:

scp -p /etc/nginx/sites-available/NAME-OF-CONFIGURATION root@THE-IP-OF-D2:/etc/nginx/sites-available/DOMAIN-NAME-OF-D1-WEBSITE
# Example
# scp -p /etc/nginx/sites-available/default root@

Log out of D1. We're done with that server.

The rest is done only on D2.

Now let's upload the D1 database to D2. Again, install Adminer to D2 unless you already have phpMyAdmin. If the D1 database name is already in use on D2, then you might need to modify the database name before uploading it. I need more information from you to assist here.

And now let's update the /var/www/ file, so the database configuration matches the login on D2 - and in case you have renamed the database, then change that too.
Let's also make sure it's owned by www-data, which I guess is your Nginx+PHP user:

chown -R www-data:www-data /var/www/

Adjust the Nginx configuration /etc/nginx/sites-available/ so it uses the root of /var/www/
And then activate the configuration:

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Test the configuration - if it returns "OK", then restart Nginx too:

sudo service nginx configtest
sudo service nginx restart

Now we should be ready to change the DNS to point the D1-domain to the IP of D2. There's way to test this before changing the DNS, by modifying your computers hosts file. If you want to be totally sure, we can do that before changing the DNS.

  • Thanks a lot @hansen :) I am going to try this out and I will let you know if this works for me.

    I use SequelPro for managing database, I use ssh key to login to the server and I have disabled root user on both the servers. Also, I have installed my sites under the sudo user's folder (~/USERNAME/public). Will this change anything in the steps that I need to follow?

    • @anshuldixit

      If you're SequelPro then you just use that as your tool, since you're probably more familiar with that.

      Instead of transferring data from D1 to D2 via SSH on D1, then you could download data from D1 to your computer and then upload to D2.
      This would probably make it a little easier than moving keys to D1 temporarily, but it depends on the amount of data, if it's worth it.

      You would replace /var/www/ with /home/username/public, and instead of SCP'ing your D1 Nginx configuration, simply copy-paste it to D2.
      And no need to run the chown command.

      Otherwise I think you're set to get started. If you get into trouble, just write a comment here and use the @ to notify me.

Have another answer? Share your knowledge.