Today we’re going to show you how we move WordPress to a new host. There are dozens of methods for migrating WordPress and pretty much all of them have pros and cons, but we’ve built some internal procedures that are battle-tested and work well regardless of where a WordPress site is hosted.
We have two main approaches:
- Moving to a new host using Interconnectit’s Search and Replace Script
- Moving to a new host with WP Migrate DB Pro
We move WordPress websites every single day, and almost every time we do it, limitations of hosting environments are always something we battle. We have a preferred method that’s incredibly fast, but we rarely find ourselves in the hosting utopia where we have all the access we need and protocols are supported by both servers.
Today we’re sharing what’s worked well with our customer’s sites in the real world. These methods should work on pretty much any modern web host, but we reserve the right to play dumb when you inevitably show us a web host that’s doing something strange and these approaches won’t work.
Getting Started with WordPress Migration
Whether you’re setting up a local development environment, a staging server, or want to migrate WordPress site to new host, you’re going to need to migrate WordPress’ files and database.
Both methods to migrate WordPress assume you already have WordPress installed on both the new and old servers. If you haven’t done that yet, follow the installation instructions for WordPress and come back when you’ve finished that step. We’ll wait.
Moving Media with SSH and the Command Line
One of the most time-intensive processes of a WordPress migration is moving media and other assets from one server to another. This can be everything from photos to videos, CSS, fonts, to plugin and theme files.
Depending on the age or niche of the website (PHOTOGRAPHERS AND FOODIES OMG) you’re moving, this can be gigabytes and gigabytes of data. Trying to download that much data to your local computer, and then upload it again can take FOR-EV-ER, so we try and copy media directly from one server to another if at all possible.
The approach we take looks something like this:
- SSH into the server where the site currently exists
- Compress the directories you need to move (typically wp-content)
- SSH into the server where the site will be moved
- Retrieve the remote files using SCP or wget
- Unzip the files and move them to the correct location
The practical steps involved in this can vary a bit from site to site, but the commands you’ll most likely need to use are tar, mv, rm, mkdir, and scp or wget
.
Here are some resources on using these commands to perform the operations typically needed to migrate a site:
- How to Compress a Directory in Linux
- How to Extract a Tar File in Linux
- Copying Files Between Linux Computers
- How to Move a Directory in Linux
- How to Delete a Directory in Linux
The idea is that you compress all of the files on the old server into one archive that can be quickly copied directly to the new server at the new web host. This saves tons of time and eliminates annoying variables like bandwidth from your ISP.
This also helps ensure some level of quality because files are only being copied once instead of twice. If at all possible we try and move files directly from one server to another, but with so many hosts not allowing SSH, we frequently end up using SFTP.
Moving Media with SFTP
It’s not ideal, and it’s usually slow, but there are frequently scenarios when our only option is to copy all of the site media to our own machines first, and then upload it to our destination server.
Download files from the old server
The first thing weโll need to do is download the site files from the old server. Assuming the site is purely WordPress, and doesnโt rely on any files outside the WordPress file structure, the only thing weโll need to download is the entire /wp-content directory.
Start by clicking the โConnectโ button in Forklift (our preferred file transfer client), and entering your FTP (or SFTP) credentials:
Navigate to your site root (on most hosts this is the public_html directory). There youโll find the WordPress core files, including the /wp-content directory:
Simply click and drag the /wp-content directory to your desktop, or other directory on your computer, to start the download. Keep in mind that all of the media uploaded to your site will be downloaded, so this process will take a while if your site has a lot of photos and videos.
Upload files to the new server
Once the download has finished, connect to the new server with Forklift, and navigate to the new serverโs site root using the same steps as above. If you see the WordPress core files, youโll know youโre in the right place.
All you have to do now is click and drag the copy of /wp-content that you downloaded to your computer into Forklift. Forklift will warn you that there is already an item named /wp-content, and ask if youโd like to replace it. Check โApply to allโ and click โReplaceโ:
The files will finish uploading to the new server and you’ll be done all done with that part of the migration. Now we can move on to database!
Migrate WordPress with Sequel Pro & Interconnect it Search and Replace DB
The basic steps for copying a WordPress database from one server to another using this method include the following:
- Export a copy of the database from the old server using Sequel Pro
- Import the database on the new server using Sequel Pro
- Update the site URL using Search and Replace DB
In this example we’re going to migrate a site from http://www.testing.dev to http://testing2.dev using Sequel Pro for exporting and importing the database, and Search and Replace DB for updating the database URLs.
Notice that we’re not only moving the database in this example, we’re changing the domain name too. This is pretty common practice, especially when you’re moving a WordPress site from a local development environment to a remote server.
One important requirement of this process is that you must be able to connect to your database remotely. If your host doesnโt allow remote MySQL connections, youโll need to export/import the database using one of the other techniques described in this article.
Export the database from the old server
Open Sequel Pro, and enter your database credentials. If you donโt know your database credentials, find them near the top of the wp-config.php file, which is available in Forklift with the rest of the WordPress core files. If the DB_HOST is โlocalhostโ, youโll need to either enter the serverโs IP address, or get the MySQL hostname from your hosting company:
Once youโve connected to the database, youโll see all the database tables listed on the left of the Sequel Pro window:
In the menu bar, click File > Export. The default options that are presented should be fine, but you may want to change where the export file is saved so it’s easiest to find later.
Import the database on the new server
Next, connect to the database on the new server with Sequel Pro using the same steps as we used before.
Once Sequel Pro has connected to the new server, delete the tables that were created when we installed WordPress. Select all tables in Sequel Pro, right click, and select โDelete Tables.โ Click โDeleteโ when Sequel Pro will asks if youโre sure you want to delete the tables.
Once theyโve all been deleted, we can import the database from our old host. Click File > Import in the menu bar. Select the database file you exported previously from the old server and click โOpenโ. Sequel Pro will then start importing the database.
Update the site URL in the database
Once the database has been imported (this may take some time depending on the database size), weโll need to perform a search and replace to update the site URL in the database. In this example weโll be updating the site URL from http://www.testing.dev to http://testing2.dev This is necessary for two reasons:
- For WordPress to work properly it has to know what the site URL is, and and it stores that information in the wp_options table.
- Any posts, pages, or custom post types that contain internal links will link to the old URL (www.testing.dev), and wonโt work properly on the new site
Search and Replace DB by Interconnectit is a really handy tool for easily performing a search and replace against a WordPress database.
To get started, download the tool, unzip it, and upload the entire Search-Replace-DB-master directory to the site root with the rest of the WordPress core files. Once it has been uploaded, open a browser window and navigate to the directory you just uploaded: http://www.testing.dev/Search-Replace-DB-master
In most cases the database information will already be populated. If not, you can simply enter the information you used to connect to the database with Sequel Pro:
Now weโre ready to perform the actual search and replace. Before we get started, itโs important to point out that this is an extremely powerful tool, and careful thought needs to go into what information weโll be modifying.
In this example, weโre changing http://www.testing.dev to http://testing2.dev. Because both of those URLs contain http://, we know we donโt need to include that in the search string. However, since weโre no longer using www. in the URL, we will want to make sure to include that in the search string. So now that we know exactly what weโll be replacing, we can enter it into the โsearch forโฆโ and โreplace withโฆโ input fields like this:
Next we’ll perform a dry run to help ensure weโll get the results we expect. Click the โdry runโ button:
If the dry run returns no results, or far more results than expected, review the strings you entered in the search and replaces input fields. If the dry run returns roughly the results youโd expect, perform a live run.
Thatโs it! The files have been uploaded, and the database has been imported and updated with the new URLs. Assuming the domain has been pointed properly, you can view the site at http://testing2.dev.
Be sure to delete the search and replace script from your server once you’re done making the URL change. Leaving it can be a big security risk.
This process is more involved than when using some of the other tools out there, but we’ve found it to be super reliable and does a fantastic job of reinforcing basic file and database management concepts. When you’re trusted with moving someone else’s website, best practices FTW!
Migrating WordPress with WP Migrate DB Pro
Here’s a secret for you: Migrate DB Pro can handle moving the database and the media in one automated process. Why’d we save this fantastic wp db migrate method for the end of the article? It’s our reward for the stalwarts, and frankly, knowing the more manual approaches will ultimately help you understand a lot of what’s happening under the hood when Migrate DB Pro is doing its thing. Knowledge is power.
I’ve relied heavily on Migrate DB Pro for 3+ years now and it’s my goto plugin to move WordPress site to new host. If you purchase a Developer license or higher (you can check out their pricing options here), you get access to several add-ons that will make migrations even easier. You can even do more complex migrations like multisite which we haven’t even touched on in this article.
First, make sure that both your current server and your new server meet the minimum requirements to use Migrate DB Pro. Here are the server requirements:
- The latest version of WordPress, or the one previous
- PHP 5.2.4+ (but no support for safe mode)
- MySQL 5.0+
- Apache 2+ or Nginx 1.4+, although it may work with other web servers that support PHP and MySQL, but they’re not officially supported
- Firefox and Webkit-based browsers like Chrome and Safari. Sorry Internet Explorer
Note: These are extremely basic requirements for a web host. If your host doesn’t meet these requirements in 2017, it’s time to move somewhere new.
Check out our WordPress Hosting comparison chart
Getting a Site Ready for Migration
Now that we have that out of the way, we can start the process of migrating your site. Install the Migrate DB Pro plugin on both servers. Also make sure that the plugins and themes directories are the same on both sites. Migrate DB Pro can’t move those directories quite yet. You’ll have to do that manually, with SSH or SFTP, but all of your media can be moved with Migrate DB Pro using the media add-on.
Once the plugin and theme directories match, log in to both sites and activate the WP Migrate DB Pro plugin using your license key. Navigate to Tools > Migrate DB Pro to work with the plugin and change the settings. This is where you’ll enter your license information.
Setting Up WP Migrate DB Pro
Migrate DB Pro gives us the ability to copy a site using push or pull. Both are extremely useful depending on your needs.
For this example, I have my site exactly the way I want it in my local development environment and I’d like to copy this site to a development server so a client can access it. I logged into the development (remote) site and changed the setting to give permissions to push to this site, meaning we can overwrite this database.
I’ll be pushing the site from my machine to the remote location. The reason I can’t pull from the remote development server is because my local development website isn’t publicly accessible, so for this scenario I’m using a Push command.
Copy the connection info URL at the top of this screen so we can use it in the next step of our migration.
Once the remote server is ready to accept a push, navigate to the Migrate tab, select “Push” and enter the connection information that you copied in the last step.
What’s being found or replaced will be automatically populated for you. If you have other things you’d like the plugin to find and replace, you can add those now on this screen.
Tables and Excluding Posts
Under tables, we can select which tables from the WordPress migrate database should be moved. This is a pretty awesome feature and the more you use WP Migrate DB Pro, the more likely it is you’ll take advantage of it.
Advanced Options
Here’s a quick breakdown of the Advanced Options available in WP Migrate DB Pro:
- Replace GUIDs – If either one of the sites has been live, you’ll want to leave this unchecked. Another example to not use this is if you’re calling anything by ID in your theme or plugin code. If you don’t know or aren’t sure, leave it unchecked.
- Exclude spam comments – Whether or not you want to migrate comments that have been tagged as spam. In most cases moving spam is probably a waste of energy.
- Do not migrate the ‘active_plugins’ setting – If you’d rather leave it to yourself to active or deactivate plugins on the new server, check this. Leaving it unchecked will ensure that the active/inactive plugin settings match on both servers.
- Exclude transients, or temporary cached data – In rare cases you may want to keep this data, but most of the time moving this data is totally unnecessary. Complex eCommerce or Membership site migrations are the most common cases where you may choose to move this data.
Backup and Migration Profile Settings
We love backups, they give us warm fuzzies knowing we have something to fall back on in case we screw up. Checking this box will create a copy of the database before migration. If you do need to restore this backup, you can find the database in the wp-content/uploads/wp-migrate-db/
directory.
Performing these backups pre-migration is definitely a best practice, but remember to go back and clear this directory of any backups you don’t end up needing. It can take up a bunch of unnecessary storage if you don’t.
WP Migrate DB Pro allows you to save your migration profile. Say you set this up and you could be doing this migration many times over in the future, you can actually save yourself the trouble of doing all of this setup over and over again. Pretty sweet time saver and also limits your ability to make errors down the road!
The Push and Pull of it All
At this point, we’re all set up and we’re ready to do this thing, right? Cool. Click the button that says “Pull” or “Push”, depending on the action you’re taking.
Woohoo, we did it! We totally just migrated a site using WP Migrate DB Pro! Not so difficult and way better than doing everything manually, right? I can’t sing the praises of the Delicious Brains team enough!
So Many Options for WordPress Migration!
These tried and true methods should definitely make your next WordPress migrate site task go smoothly. We fully understand that there are about 4,948 other methods that can be used to move a WordPress site, and they all have merits in different scenarios.
These methods that have been the most efficient and reliable over the course of several hundred (maybe thousands?) of WordPress migrations performed by our team, so there you have it!
How are you moving your WordPress sites? Any challenges you’ve run into we can help you figure out? Hit us up in the comments!
15 responses to “How We Migrate WordPress – A Complete Guide”
Woow .. All this to just move a WordPress website? Maybe I missed something then, because I never used this much of work to move clients websites .. Hmm .. Maybe I should, and raise my pay .. =)
If you’re providing more value then maybe you should?! If you have secret sauce we don’t know about feel free to share it!
Yes Leif….do share please? How do you do it?
This would be a great presentation at a WordCamp- Great post Ozzy!!
I totally agree! Ozzy would be a great person to give it too ?
Thanks for this write up of Migrate DB Pro. Sounds like a great tool to have. I usually use DesktopServer when developing locally or do it manually if that won’t work.
DesktopServer is a great tool, Stephanie! (We use it quite a bit, as well)
Just keep the tools we went over in the post in mind when moving sites from one server to another, or bringing one down to work locally or pushing it up after you’re done with local development. They’ll save you tons of time!
Excellent article, thank you ! I went ahead and bought a license to WP Migrate DB Pro after the media files add-on came out, it is a great feature.
A couple of things that I run into quite frequently that might help others: the media files add-on I believe moves everything in the /uploads folder. I’ve found some older sites have a huge amount of data in that folder that does not belong to WordPress, as such you might timeout. Also, I frequently get the problem of mismatched table prefixes. I’ve used the plugin Change Table Prefix to remedy this.
If you use command line tool, you should check out WP-CLI, which has a powerful command for search and replace string in the DB. In case you don’t have access to command line on the host, these solution are the best.
Definitely, Anh! We love WP-CLI but lots of hosts don’t support it out of the box unfortunately. We tried to write this in a way that would cover as many hosts as possible. Thanks for chiming in!
I use the Duplicator plugin to migrate WordPress sites every day (https://en-ca.wordpress.org/plugins/duplicator/). It packages up your WP site and creates a downloadable zip file containing files and database. Along with that it provides an installer.php file. You simply copy the two files into the root directory of your destination and load the installer.php. It somes with Search/Replace built in, so it takes care of modifying the URLs for you. Highly recommended!
We’ve tested Duplicator a few times in the past and the results have been pretty mixed. On smaller, less complex sites it seems to do a pretty good job, but that would really only cover a small percentage of our customers. If your site has a ton of media files or a sizable database, Duplicator just isn’t a very good option in my experience.
The processes we use have worked well for sites ranging from a simple local business site up to a massive multisite network of publishers. Sometimes they could be considered overkill, but since we use the techniques so often it really wouldn’t save us any time to use something like Duplicator, so we go with what we know! ?
Thanks for saving us some time!!
Leif – Would love to know how you do it so quickly ๐
Woow .. This to simply move a WordPress site? Possibly I missed something then, since I never utilized this a lot of work to move customers sites .. Gee .. Possibly I ought to, and raise my compensation
Check out ManageWp from (now GoDaddy) Orion. I’ve used it on a few client sites and even my own. Works great and includes backup, updating themes and plugins and moving sites between servers.