How to Migrate a WordPress Site

I spend a lot of time working on WordPress and find myself being asked how to migrate a WordPress site often.   So here it is in 6 simple steps.

Step 1 – Make a local copy of your full WordPress site files via FTP

Connect to your existing webspace via FTP and sync a directory on your local disk to the document root which contains your live WordPress install. Copy everything. The WordPress core files, your uploads, the themes, the plugins – everything. This can take a while so best to get this step 1 under-way so it’s copying across while you move on to the next few steps.

If you’re working with a huge file size you may find it quicker to log in to cPanel > File Manager > and use the compression tool to zip up the files and download.

Step 2 – Get a dump of your WordPress database using phpMyAdmin

Any reputable hosting provider is going to offer phpMyAdmin to their users – usually accessed via your cPanel. Follow these steps to get your existing database exported:

    1. Connect to the instance of phpMyAdmin which provides access to the database for your current site. Enter your credentials to log in to the management interface.
Figure 1

(Fig. 1) Select your WordPress database from phpMyAdmin’s list of databases

    1. Select the database for your existing WordPress installation from the list on the left.
    2. Click ‘Export’ at the top of the window.
(Fig. 2) Click the 'Export' tab at the top.

(Fig. 2) Click the ‘Export’ tab at the top.

  1. Ensure that the radio button for the ‘Quick’ export method is selected. Click the ‘Go’ button to download a .sql file containing a dump of your current database table structure along with all of your existing data.
(Fig. 3) Check the 'Quick' export method radio button and click 'Go' to download your database dump.

(Fig. 3) Check the ‘Quick’ export method radio button and click ‘Go’ to download your database dump.

 Step 3 – Import your database

Now you have to reverse the export process to import your database to the new site.

  1. Create a new database in your new hosting panel. Make sure to note down the database name, username and password as you’ll need those later for your wp-config.php file.
  2. Log in to the phpMyAdmin interface for the new database.
  3. Select the new database from the list on the left (see Fig. 1, above).
  4. This time, click the ‘Import’ tab at the top of the window.
  5. Now you’ll have to select the file you just downloaded containing your database dump so that you can upload it here. Click the ‘Choose File’ button and locate the .sql file downloaded during Step 2, above.
  6. Click the ‘Go’ button to import your data.

Step 4 – Apply database migration fixes

  1. You’re already where you need to be – in your new phpMyAdmin click the ‘SQL’ tab up at the top and paste the following SQL query in the giant ‘Run SQL query/queries on database…’ field and change the http://www.newsiteurl.com to reflect the root level of the site you’re transferring to:
    UPDATE wp_options SET option_value = 'http://www.newsiteurl.com' WHERE option_name IN ('siteurl', 'home')
  2. Click ‘Go’ to execute the query above. You should see a green message box saying that two rows were changed.
  3. Once that’s done, time for a second fix. Run this next SQL query in the same way (this time one row should be changed):
    UPDATE wp_posts SET post_content=(REPLACE (post_content, 'http://www.oldsiteurl.com','http://www.newsiteurl.com'))

Step 5 – Upload your WordPress files to the new webspace via FTP

  1. When you’re ready, connect to the FTP host for the new site and upload the entire contents of the site to its new home.
  2. Edit your /wp-config.php file to include the correct information for your new database (per 3.1 above)

Step 6 – Find & Replace File Paths, and Resave Permalinks

  1. Run this  Search and Replace for WordPress Databases Script to safely update the rest of your file paths (this script is awesome – it runs almost instantly). This ensures your migrated version of the site is getting all the images, links and so on in the right place.
  2. At this point you need to test your newly uploaded site by logging in to the admin panel. If you get in without any problems, go to Settings > Permalinks and click ‘Update Permalinks’. This ensures WordPress can write to the .htaccess file and will make internal pages acessible. If it can’t for some reason, you should see a message reading something along the lines of “If your .htaccess file were writeable, we could do this automatically, but it isn’t.”  In that case, make sure that you edit your .htaccess file to reflect your current domain configuration:
    # BEGIN WordPress
    
    RewriteEngine On
    # RewriteBase must reflect the root of your WordPress installation
    # So, if you're running WordPress at http://www.domainfoo.com/bar
    # you'll need to set this to 'RewriteBase /bar'
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    # END WordPress

    If WordPress is unable to modify this file automatically it’s because of a permissions problem. The .htaccess file needs to be writeable by WordPress so you manually give it this permission (via FTP or cPanel) or failing that, contact your hosting provider for assistance with this.

  3. That’s about it!

Step 7 – Aftermath

At this point you should be successfully migrated. Now you just need to thoroughly check through your site to make sure everything is working correctly.  Once you’re totally happy and 100% sure you’ve made a successful migrate you can clean up your old webspace (remember to take a backup) and get on with your life!

I hope you enjoyed this tutorial and found it helpful. Feel free to write a comment, ask a question, or let me know if I missed something!

2 thoughts on “How to Migrate a WordPress Site

  1. sam says:

    I believe that using a wordpress plugin like duplicator is better as seen here.
    http://www.wpcares.com/migrating-wordpress-site-easily/
    Is there any flaws to use this plugin?

    1. Maeve says:

      There are many plugins to help migrate or clone your WordPress site. As someone who builds and migrates a large handful of WordPress sites every month, I have found the manual migration method described in this post is the most reliable and efficient way to handle it. That’s not to say plugins like the one you suggested don’t work, just that the manual migration method works best for me. If you’re unfamiliar or uncomfortable with using cPanel, FTP or PHPMyAdmin then perhaps a plugin would work better for you.

Leave a Comment

Your email address will not be published. Required fields are marked *