How to migrate your WordPress’s staging website to your live site
A common and good practice is to build your website in a “staging” location. This allows you to get everything customized the way you need before “going live” with your website. This is especially helpful if you’re replacing an old website, and you don’t want any downtime. You can completely build your new website in the staging location, and when you’re ready, move that to your actual “live” website.
But actually handling that migration from the “staging” site to the “live” site is a complex thing to do. Some webhosts, like Flywheel, give you the tools to do a 1-click migration from your staging site to your live site.
But most web hosts do not have an option like this yet.
There are a few WordPress plugins out there that aim to make migration easier. For reference here are a couple of those plugins:
- WP Migrate DB and it’s upgraded pro version (which we highly recommend if you’re struggling)
- All in one WP Migration
Migration options if you’re struggling
While the above plugins are great and typically work well, we’ve also heard from quite a few customers who struggle to use these migration plugins successfully, as they can be complex. So if that’s you, we’d like to give you a few options:
- Use a staging service like BlogVault. This is undoubtedly the easiest option, as it’s a one-click operation.
- Follow our step-by-step guide using WP Migrate DB to do it yourself (below).
- Our team is available for hire if you’d like us to handle it for you. Contact us.
1. Using a Staging Service
Like I mentioned, handling staging and migration is not a simple thing. If this is something you’ve been struggling with for a while and just want to get it done with no more headaches, I would highly recommend taking a look at BlogVault’s staging service.
With it, you can clone your entire site with 1 click, instantly creating an exact replica staging site on BlogVault’s servers. Once you’re sure your staging site is good to go, you can push the entire staging site back to your live site with, again, a single click.
This is truly the headache-free option, and having used it myself for some projects, I have to say that it is pretty impressive. But like most things that get rid of headaches, there’s an added cost, starting at $89 per year. So you’ll have to decide whether that cost is worth the time you’re saving. It’s also worth factoring in the fact that BlogVault can also act as a backup for your site, and they also have a malware protection system if you use their PLUS plan.
While it’s not for everyone’s budget, I just wanted to make sure you were aware of that option before we dive into the steps to do it all yourself manually.
2. Do-It-Yourself Migration
The very first thing to do before migrating is to back everything up. This way, if anything goes wrong during the migration, you won’t lose any of your hard work.
There are two extremely important things that need to be backed-up and then moved properly when migrating from a staging site to a live site:
- The site’s files
- The site’s database
What you need before starting:
- FTP access from your webhost, and an FTP program like Filezilla
- Access to your database through something like PHPMyAdmin, which is typically found in your web-hosting account
Step 1. Backing up the files
With WordPress, all of your unique files are stored in the “wp-content” directory. Using your FTP program, log in using the information for FTP provided to you by your webhost.
Once you are logged in, browse to the “root” directory of your live site’s WordPress. This is the directory which contains the “wp-content”, “wp-admin”, and “wp-includes” directories, as well as a few other files created by WordPress. Typically this is found in the “public_html” directory.
Then, download your entire wp-content directory to your local hard-drive to back it up. This can take a some time if you have uploaded large files, or if your internet connection is slower. While that is downloading, you can go and make a backup of your database.
Note that you must backup both the staging wp-content directory and the live wp-content directory to make sure you have no data loss. So repeat these backing-up instructions for your staging site as well.
Step 2. Backing up the database
Anything that isn’t a file, like text you’ve saved in a post or text area, is saved to the “database”. This is the second part that needs to be backed up and moved. Typically your webhost will give you access to your database using something like PHPMyAdmin. If your hosting account has cPanel, it may even give you the option to download the database directly.
Now, you’ll need to download a backup of both your live site’s database, and your staging site’s database, to ensure you have a full backup and won’t lose any of your data.
In PHPMyAdmin (or if you’re using a different program like Sequel Pro), locate the database for your live site. Then, select all of the tables and use the menu options to export them.
Repeat this for your staging site as well to back it up.
Step 3. Migrating the files
Once you have completed the backup of the “wp-content” directory, it’s time to move it. If you haven’t completed all of the backup steps above, make sure you do those first. Otherwise you could have major data loss that is not able to be fixed.
Browse to your live site’s root directory again (the one that contains the “wp-content”, “wp-admin”, and “wp-includes” directories), and replace the entire live site’s wp-content directory with your staging site’s wp-content directory, which you’ve downloaded at the second part of Step 1 (above). You’ll want to be very careful here to make sure you are moving from the staging site to the live site, and not the other way around.
You’ll do this in your FTP program again by dragging and dropping the staging site’s wp-content directory into the root directory of the live site.
Step 4. Migrating the Database
One of the main problems that needs to be solved is properly replacing your staging domain name wth your live domain name everywhere it exists in your database. Typically this could exist in several hundred places. For example, if you uploaded a photo, it will be linked in the HTML using the staging domain. So the link to the photo might be “www.staging.mywebsite.com/wp-content/uploads/photo.jpg”. But after you migrate, you need it to be “www.mywebsite.com/wp-content/uploads/photo.jpg”.
Obviously going through and replacing each of those manually could take hours, if not days, and you’re likely to miss one or two, which can be very frustrating. But the free version of the WP Migrate DB plugin does all of that for you flawlessly. You simply use its “Find and Replace” functionality to replace any instances of your staging domain with your live domain. It is extremely smart in the ways that it does finding and replacing, and finds things that most other migration plugins miss.
Once you’ve completed the find and replace, to replace your staging domain with your live domain, download the database it gives you.
Then using your PHPMyAdmin, SequelPro, or some other way you are able to access your database, replace the tables on your live database with the tables you downloaded here from WP Migrate DB.
And that’s it!
Migrating a staging website to a live website is definitely a complex thing that requires a lot of carefulness and attention to detail, as well as a commitment to properly backing everything up. It also requires a pretty clear understanding of database tables and FTP (File Transfer Protocol). But with a commitment to those things, you can make it happen.
If you’d rather hire someone to handle all of that for you, reach out to us and we can make it happen for you.