Having a local WordPress install is a key workflow requirement for designers and developers alike. Whether you’re developing a plugin, putting the finishing touches to a theme or just speccing out changes for a client, a local setup boosts productivity by letting you work quickly and safely on your own machine. At some stage though, you’ll naturally be looking to take the next step.
This article will show you how to go about migrating your local content to the web. To get you comfortable with the overall principles, we’ll focus on doing this manually, before listing some plugin solutions to help you streamline the process down the line.
First though, let’s make sure our bases are covered with a look at the tools you’ll need to follow along.
Tools Required to Migrate Your Content
The more hardcore amongst you are of course free to use Vim or Emacs if the selections above are not to your taste.
Lastly, you’ll need an FTP client to upload your local WordPress files to the server. Again, options here vary across platforms. Without getting bogged down in the intricacies of competing solutions, here is a brief list of common options to consider for Mac and PC:
Once you’ve made your choices, we’re almost ready to get going. Before we dive in though, let’s briefly discuss the built-in export tool that comes with WordPress and how it fits into the overall migration picture.
Can’t I Just Use the Built-in Export Tool?
If you’re simply looking to transfer content from one site to another, WordPress’ built-in export tool is a very handy solution. To use it, go to Tools > Export from your website’s dashboard.
You’ll then see a list of simple export options for content types such as comments, posts and pages.
This produces an XML file suitable for re-importing into another WordPress install. If you’re after a little more control over the export options pictured above, the Export Plus plugin is worth a further look.
However, this technique won’t cover theme changes, images, or anything else outside of the core WordPress files that you may have altered.
In this article we want to address moving the entire site – not just parts of the content – so we’ll turn our attention at this stage back to our manual migration process.
Exporting Your Local Database
To move the site we need to do two basic things:
To keep things nice and organized, we’ll also need a place to gather everything locally while we’re doing this. In this case I’m going to create a folder called /migrate-to-live-01. Copy the contents of your local WordPress install into that folder.
With our folder in place, make sure your local web server is running and browse to your copy of phpMyAdmin to begin the database export. This will typically be located at http://localhost/phpmyadmin.
Select the relevant database and click Export from the top menu in phpMyAdmin.
You should now have a .sql file downloaded to your machine, in my case my-database-export.sql. Place it in /migrate-to-live-01 and we can look at making some small but necessary changes to it.
Adjusting File Paths
The file paths in your current exported database will cause problems when imported into the live site. Links to existing content will start with a local path such as http://localhost which, naturally, will not be correct in the live environment. We’ll fix that now to save having to do anything too involved on the server.
This is as simple as firing up your text editor of choice, opening your exported .sql file and doing a search and replace. In the example below I’m replacing http://127.0.0.1/wp-example with http://www.mylivesite.com.
One handy alternative to avoid doing this in a text editor, or via phpMyAdmin on the live server, is to use the WP Migrate DB plugin.
Doing this in a text editor to begin with though is a handy way of getting a feel for what’s going on under the hood.
With that done, let’s get the live database up and running.
Setting up the Live Database
We’re assuming that you’ve already signed up to a paid hosting solution with PHP and MySQL that matches the current WordPress hosting requirements. With WordPress now powering nearly a quarter of the top 10 million websites online, it’s increasingly rare to come across a hosting company that doesn’t support these requirements, but it’s always best to check.
The exact hosting package and provider you should go for is another subject entirely – one we don’t have room to fully explore here. For the purposes of this article, we’re taking it as read that you’ve selected a WordPress-friendly package that comes with phpMyAdmin installed on the server.
Okay – back to business. We need a remote database set up to import our .sql file into.
Log into your hosting account’s control panel and navigate to the database section to add a new database. Options for doing this will vary from host to host but the requirements are the same. You need to create a new database and create a user and password to access it.
Check with your hosting provider if you are unsure how to do this. They will will usually have a simple set of steps to follow as in this example with a cPanel setup. The WordPress help pages also offer excellent detailed guides for doing this with cPanel, Plesk and phpMyAdmin.
Whichever solution you use here, make sure to make a note of the database name, username and password at this point.
Migrating Content to the Server
It’s now time to migrate our site. The first step is importing our local database. To do this, simply navigate to phpMyAdmin on the server, open the database you just created and import the local .sql file.
All being well, our database is now sitting pretty on the server waiting for someone to talk to.
Before we move the rest of our files across, there’s one small item to be taken care of locally – editing wp-config.php to include the correct database credentials.
Open up wp-config.php in your editor of choice and amend the following lines:
The final step is now transferring the WordPress files themselves across to the server.
We’re assuming in this case that there isn’t an existing WordPress install that we’re trying to target so it’s simply a case of FTPing all the files in our local install across into the remote root directory (or a specific sub-folder if you are choosing that option).
Congratulations! At this stage your WordPress site is migrated. The final step before testing is accessing the admin panel and rejigging your permalink settings to make sure they match what you had on your local setup.
To do this, log into your new live at http://www.mylivesite.com/wp-admin.php and go to Settings > Permalinks.
With that done, it’s time to take a final tour around your live site and test core functionality to make sure nothing is broken.
A Word about Gotchas
With the range of potential local and remote setups, not to mention the options available within WordPress itself, the possibility of something going slightly awry along the way is not a remote one.
Learning to calmly troubleshoot WordPress server problems is a skill in itself and one that requires practice. If you run into problems, review the steps above first and then begin your troubleshooting with the excellent Moving WordPress guide and followed by a search of the Troubleshooting pages.
Making note of specific error messages you run into along the way will also make tracking down root causes substantially simpler.
After you’ve gone through these manual migration steps a few times, you’ll naturally start looking for more automated solutions to help streamline the process and remove some of the potential for human error.
Here’s a brief list of plugins currently available that are worth following up on after you are comfortable with the steps above:
Migrating a local site to a live server can be a daunting proposition if you’ve never done it before but hopefully the steps above have proved it’s really not such a complicated process.
You’ll learn more as you go along but stick to the basic sequence we’ve outlined and you’re off to an excellent start. Let’s recap those points:
Make sure you have the right tools to begin with.
Export your local database and tweak the URL paths.
Set up your remote database and import the local database content.
FTP the local WordPress files to the server.
Adjust your live permalinks and test the site thoroughly.
Feel free to share this article if you found it helpful or drop us a line in the comments below if you have any questions or feel we’ve missed anything.
Good luck with your big move!