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
- Log into your live site
- Install UpdraftPlus
- Create a backup
- 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.
- Log into your new dev site
- Install Updraft plus
- On the Existing Backups tab for Updraft Plus, click the link to Upload backup files and choose your backup files
- Refresh the page once it’s completed uploading
- Click to restore and tick everything to restore
- 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.
- SSH to your old site, navigate to the webroot folder
- Run: zip -r backup.zip wp-content
- Run: mysqldump -u username -p dbname > backup.sql (then hit enter and then enter password)
- SSH to your new site
- SFTP oldipaddress
- Navigate to webroot
- Run: get backup*
- Extract these zip files to somewhere then copy the wp-content/* to your new wp-content folder
- 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.
- Download the Interconnectit search/replace script from here: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
- Extract the files, upload the folder to your /var/www/yourdomain/ folder using Filezilla or Cyberduck or similar
- Visit your sitedomain.com/searchfolder in your browser – e.g. http://dev.wpintense.com/searchreplace
- It will automatically pick up database credentials
- Enter www.yourdomain.com in the search box and dev.yourdomain.com in the replace box
- 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:
- Run the search replace script again by opening http://dev.yourdomain.com/searchreplace
- Enter dev.yourdomain.com in the search box, www.yourdomain.com in the replace box
- Hit live run and wait
- Visit your DNS and edit the A records for www.yourdomain.com and yourdomain.com to point to your new IP address
- 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!
- Manual update for Super Speedy Search required - September 4, 2020
- How to enable debug.log to collect WordPress error messages - September 2, 2020
- More speed, more updates, and a bit of a roadmap for our plugins - July 2, 2020