Move WordPress to a new VPS

Move WordPress to a new VPS

Sometimes a change of scenery is really good for you, sometimes it’s even true for your WordPress site. For example you want to move your website from a server located in Germany to one of your servers in the US for better connectivity for the American users. I’m using DigitalOcean as my VPS provider and you have the option to take a snapshot and move the whole server, but in my case this was not what I wished to do, I wanted to move WordPress to a new server setup I just made, so in this tutorial I will walk you through how to backup your file contents and your database and migrate it to the new server, both servers being of the flavor Ubuntu 14.04 LTS.

Move WordPress using SCP

We’re going to use a really neat tool called safe copy which you can use to securely copy files from one server to another. But before we begin we will make sure that everything is setup properly.

We have two servers named test1.jejje.net and test2.jejje.net and we need SSH access to both of them, let’s say we have a user with the username jejje on both servers for convince, and our files are located within our home directory /home/jejje/public_html. Great! Let’s begin by gzipping our folder.

tar -zcvf public_html.tar.gz /public_html

Now when we’ve zipped our folder we can securely copy it onto test2.jejje.net from our server test1.jejje.net. Let’s assume we wish to move the files to the same folder but on the new server using the SCP tool that I mentioned.

scp public_html.tar.gz [email protected]:/home/jejje/

A password prompt will pop up and all you need to do is enter it and wait for the files to transfer, it won’t take long at all depending on the size of your website.

Backup your WordPress database

For this step we need our MySQL credentials, let’s say they are as following; jejje and password – and the database we are going to use is named wordpress. We will want to save our database into a .sql file and the name doesn’t matter so let’s just call it dump.sql, with all of these credentials we can now finally make a backup dump of our wordpress database with all it’s tables.

mysqldump -ujejje -ppassword wordpress > dump.sql

This command will login to your MySQL account and dump the wordpress database into the textbased dump.sql file, great! With this file and the WordPress files we’ve already sent over, we’ll soon be up and running on our new server, but first we’ll need to use the SCP command to send it to the new server. It’s pretty much the same as before.

scp dump.sql [email protected]:/home/jejje/

When the magic is done, you can now login into your second server, in our case the test2.jejje.net server.

 Restore WordPress on the new server

We now have two files in our /home/jejje/ on test2.jejje.net, we have the gzipped file with our WordPress files in it, we need to unpack it to the correct folder.

tar -zxvf public_html.tar.gz

This will now unpack and there are only a few steps left to finish our restore of our WordPress migration, we’re still missing the database and we’ll get to that right now. I am assuming that you already have a database setup on your new server named wordpress just as the old one, alongside with a matching MySQL account for convenience_._

mysql -ujejje -ppassword wordpress < dump.sql

If everything has gone as it is supposed to, which it mostly does. You could now change your DNS settings to point to the new server and everything should work just as nothing has happened, we just have to wait for the DNS to propegate (which I do hate, I know I shouldn’t but I do). 

Rounding up

This way we’ve done it today is by far the simplest road to travel when we’re working with our own servers. This way prevents the issues that may occur if we had used an FTP and PhpMyAdmin as an example, I myself encountered that the files took ages to transfer on my slow Internet, and the PhpMyAdmin aspect of it often failed because of file upload limits. This was the case when I transfered a clients WordPress blog that had been posting on a dailiy/weekly basis with a ton of plugin data in the database. His dump.sql file was actually more than one gigabyte, instead of the regular two to ten megabytes, and that’s when I figured this would be the most painless way to do it – and I highly recommend it.

One thing to mention though is that errors might occur if you decide to change your database name from wordpress to wordpress_blog, but it’s easier to change the name afterwards. I wish to the best of luck on your future WordPress setups!

Jimmy Nelsing's Picture

About Jimmy Nelsing

I'm a computer enthusiast who loves the web and web development, I've used Wordpress for a long time on and off for different web pages for many years. I also like to develop in PHP, especially with Laravel and have also started with Java programming as side projects - testing out Bukkit and Android.

http://jejje.net/

Comments