How We Migrate WordPress – A Complete Guide

Looking to migrate your WordPress website to a new host? Here’s our complete guide of how to do it right.

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:

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:

  1. SSH into the server where the site currently exists
  2. Compress the directories you need to move (typically wp-content)
  3. SSH into the server where the site will be moved
  4. Retrieve the remote files using SCP or wget
  5. 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:

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:

connect-with-forklift

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:

download-wp-content

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”:

overwrite-wp-content

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:

  1. Export a copy of the database from the old server using Sequel Pro
  2. Import the database on the new server using Sequel Pro
  3. 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:

sequel-pro-connection

Once you’ve connected to the database, you’ll see all the database tables listed on the left of the Sequel Pro window:

sequel-pro-connected

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.

delete-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:

  1. 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.
  2. 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:

search-and-replace-db-credentials

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:

search-and-replace-strings

Next we’ll perform a dry run to help ensure we’ll get the results we expect.  Click the “dry run” button:

search-replace-dry-run

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.

Migrate DB Pro Plugin Dashboard
Welcome to the WP Migrate DB Pro Dashboard

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.

Click the long URL and copy it to the site you’re migrating to/from.

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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!

Ryan Sullivan Avatar
Chief of Staff

15 min read