How to migrate your WordPress site to a new host

The most reliable way to migrate your site is using the manual method in this article. However, the manual method can be tricky for less-technical users.

The Duplicator plugin promises to make this easy, but I’ve found it to be incredibly buggy and has failed me on numerous ocassions. Because of this, I use UpdraftPlus for easy migrations. You can make this simpler by buying the UpdraftPlus Migration extension, but it’s also possible to do it for free fairly easily using the guide below along with a search/replace script which covers the functionality provided by the Migration extension.

Migrating your site using UpdraftPlus

Create a backup of your live site

  1. Log into your live site
  2. Install UpdraftPlus
  3. Create a backup
  4. Download the backup files (there will be 4 or more files)

Restore to your dev/new site

Note: Restoring to your dev site from your live site will copy across all user accounts from your live site, replacing any existing user accounts you have on your dev/new site. If you have just set up your new/dev site, you will probably have just an admin account for WordPress. You need to use this for this steps below, but after ther restoration is complete that admin account will be replaced by the credentials from your live site.

  1. Log into your new dev site
  2. Install Updraft plus
  3. On the Existing Backups tab for Updraft Plus, click the link to Upload backup files and choose your backup files
  4. Refresh the page once it’s completed uploading
  5. Click to restore and tick everything to restore
  6. Because you have a different domain in use, it will warn you it’s a migration, not a restoration – just skip that – we will search/replace manually below to complete the migration

Migrating your site manually

This is a technical checklist – if you are unfamiliar with SSH/Putty, you should use the UpdraftPlus approach to migration above.

  1. SSH to your old site, navigate to the webroot folder
  2. Run: zip -r backup.zip wp-content
  3. Run: mysqldump -u username -p dbname > backup.sql (then hit enter and then enter password)
  4. SSH to your new site
  5. SFTP oldipaddress
  6. Navigate to webroot
  7. Run: get backup*
  8. Extract these zip files to somewhere then copy the wp-content/* to your new wp-content folder
  9. Then replace the DB using: mysql -u username -p dbname < backup.sql

Note: The above approach presumes everything custom in your site is in wp-content. If it’s in /assets/ or somewhere instead, you’ll also need to copy those files over.

Search/Replace in your database to change all www.yourdomain.com references to dev.yourdomain.com

If you visit your copied-website now, you will see everything from your live site, but if you click any links you will end up back on your live site. This is because the backup you copied across has references to your live domain name. The tool and steps below allow you to search/replace all the correct places to change these hyperlinks to point to your new dev hyperlinks.

This is the only tricky part about using Updraft Plus and in fact if this is too tricky for you, you can go UpdraftPlus premium and it includes this functionality in the plugin.

  1. Download the Interconnectit search/replace script from here: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
  2. Extract the files, upload the folder to your /var/www/yourdomain/ folder using Filezilla or Cyberduck or similar
  3. Visit your sitedomain.com/searchfolder in your browser – e.g. http://dev.wpintense.com/searchreplace
  4. It will automatically pick up database credentials
  5. Enter www.yourdomain.com in the search box and dev.yourdomain.com in the replace box
  6. Hit Live run and wait

How to make your dev site live

Once you are happy that the performance of your new hosts outperforms your old hosts, you can flip the switch. Here’s how to do it with zero downtime:

  1. Run the search replace script again by opening http://dev.yourdomain.com/searchreplace
  2. Enter dev.yourdomain.com in the search box, www.yourdomain.com in the replace box
  3. Hit live run and wait
  4. Visit your DNS and edit the A records for www.yourdomain.com and yourdomain.com to point to your new IP address
  5. Once you have completed this final search replace and confirmed you are live, you should delete the searchreplace folder using Filezilla as it’s a major security hole leaving it there.

That’s it – you’re live!

Chat to me

Dave Hilditch

Founder at WP Intense
Dave has been programming since 6 years old and has been developing WordPress plugins, themes and websites since 2010. In the past he built the browse view technology for Skyscanner and now he helps clients with interesting website challenges.

He is always on at least one of his computers when he's awake, so get in touch and he'll get right back to you.
Chat to me

Latest posts by Dave Hilditch (see all)