Migrating WordPress From One Server To Another

KB ID 0001315 

Problem

I have to say before I start, that most of the credit for this article lies with Allen White from www.techieshelp.com. Who gave me the three most important pieces of information that you need to migrate your WordPress site. 

Three Things You Need;

  • The contents of your wp-content directory.
  • The contents of the root of your site.
  • A backup of your database, (this is a lot easier than you think).

Now there may be a couple of exceptions, for example, if your site runs https you might also need a copy of your certificates, and if you have any sub-folders in your site you will also need a copy of those folders as well.

Would it be easier to get an application or plugin to do this for me? Well I use UpdraftPlus and I also use BackWPup (both of which are free). But to be honest you just need access to the site from an FTP/SFTP client (I prefer FileZilla, again because it’s free), or you can simply use WinSCP, (again free).

Solution

Before You start: You need a WordPress server setup with a blank install of WordPress ready to accept your data. I’m not covering that in this article. This article is primarily to cover migrating your site contents. (Though watch this space, I’m going to post a full, WordPress install on LEMP article soon).

To make things simple, set the new database with the same name, username, and password, (get these from your live sites wp-config.php file).

I would also update your live site to the latest version of WordPress before you migrate, Or when you connect you may see a dialog about updating the database and have a bit of downtime.

Backup Your WordPress Data

First connect to your live website and download a copy of your ‘wp-content’ folder;

WP Content Directory

Note: The more eagle eyed among you will notice I’ve got an ‘extra’ folder in my site, called ‘KB’  that folder will also need downloading.

Now download ALL the files in the root of your website.

HTML Root Directory

Now to get a copy of your database, you will need to know what it’s called, if you have forgotten, open your wp-config.php file (it’s in the root of your website,) with a text editor, and look for the following;

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'NAME-OF-YOUR-DATABASE');

You will also need the root password for your SQL installation, it will be blank unless you have changed it when you installed MySQL or MariaDB, (by running ‘sudo mysql_secure_installation‘).

Connect to your server via SSH or log directly onto it’s console; and run the following command;

mysqldump -u root -p NAME-OF-YOUR-DATABASE > data-dump.sql

Supply the password and a backup of the database will appear in the folder you are in, (download that also).

Export SQL Database

I don’t know the SQL Root Password? You can get the username and password that the SQL user uses, (again from the wp-config.php file, and use (mysqldump -u {username} -p {password} {database name} > data-dump.sql).

Restoring Your WordPress Data

Database

Now connect to your new WordPress site with your FTP/SFTP client, and upload the data-dump.sql file.

Connect to your site via SSH, and navigate to the directory you have just uploaded the data-dump.sql file to. You can import the data into your new database with the following command;

mysqldump -u root -p NAME-OF-YOUR-DATABASE < data-dump.sql

Note: The command is the same as above, but note this time you use the ‘less than’ symbol.

Supply the root password for the destination SQL server.

Data

Restore the contents of your wp-content folder that you backed up earlier directly over the top of the wp-content directory on the new server.

Upload wp-content

Repeat for any other folders BUT NOT wp-admin or wp-includes.

What this does;

  • Restores your theme(s) and CSS files.
  • Restores your plugins.
  • Restores your WordPress users, and passwords
  • Restores all your posts/pages and media
  • Restores all comments.

Finally restore the files that are in the root of your website, (except the wp-config.php file, as I’m assuming the new site already has a new wp-config.php file with all the right settings in it). 

 

Can this be done any quicker? Yes if you use the BackWPup plugin, you can get it to do a backup of SQL for you, and backup all the files and folders in your site. I back these up to DropBox automatically, so every day they are already on my laptop, this saves me having to download everything. It also means I can rebuild my website if my web server breaks.

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *