Migrate a WordPress Website to a New Server

Cloning or migrating a WordPress website on a new server can be done in 5 steps. I wish someone had written this simple guide for me back when I was figuring out all this stuff. So I decided to write it for someone just like me, who may go looking for this. Here’s how you migrate a WordPress website:

Step 1: Create a Fresh WordPress Install

First you’re going to create a fresh install on your new server. Even if you intend to migrate the domain, at first you’re going to have to give this install a different one. If you’re cloning the website as a backup, the different (sub)domain name is fine.

IMPORTANT: Write down name of the database that will be associated with this install. If this is not easily accessible during the installation process (although it should be), make sure to log into phpMyAdmin (easily accessible through cPanel) to grab that database name OR open up the wp-config file on the server and make note of the name from there.

Step 2: Download the original website’s database

a. Log into the original website’s phpMyAdmin. Select the database associated with your website from the left panel, and then select Export from the top panel.

b. Select Custom underneath Export method. Check Rename exported databases/tables/columns under Output Method. 

c. In the modal that pops up, rename the database to match the name of your fresh install database. Save and close, then scroll all the way down and hit Go.

Step 3: Upload the original database to the new database

a. Navigate to phpMyAdmin on the new server.

b. Select the correct database from the left panel and go down to where it says Check All, select that, and then open the actions drop down and select Drop.

c. Then select Import from the top panel. Drag and drop the database file you downloaded from the original website onto the window to upload it.

Step 4: Replace old URL instances with the new one

I’ve added the necessary code to a gist. But you can also just copy the code from here:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

a. Click on the correct database in the left panel and then select SQL from the top panel. Paste the code from the Gist (above) into the text box.

b. Replace http://www.oldurl with the old URL (make sure there’s no trailing slash)

c. Replace http://www.newurl with the new URL (make sure there’s no trailing slash)

d. Click Go. (You can first use the simulate button to test what effect the query will have first.)

Step 5: Replace the new wp-content folder with the old wp-content folder.

This is super easy, download the original wp-content folder, and then upload it to the new server, replacing its contents.

That’s it, you’re done! Everyone can log in with their usual credentials and everything has been kept intact.

One of the things we offer over at Wanderoak, is a weekly off-site backup service. We clone your entire WordPress website on a separate server every Friday, in case of emergencies, hacks, or any server issues your main server or web host encounters. So I follow this exact guide so often that the hands-on part of this entire process takes me less than 10 minutes. Seriously. It’s that easy.

P.S. Need to point an old domain to a new one? I’ve got you.