Wordpress Migration

From iMediaWiki
Jump to: navigation, search

At some point in your work with Wordpress, you will need to migrate your site between servers. This article details the process of moving your Wordpress site architecture and database between environments. For more information on Wordpress in general, consult Category:Wordpress.

The Basic Procedure

The basic Wordpress migration process follows a simple procedure:

  1. Export Test DB as a .sql file (for this tutorial, "mysite.sql")
  2. Duplicate/backup the Test Wordpress folder on your local machine
  3. Set up a new DB in Production
  4. Edit wp-config.php on your local machine, add new database information
  5. Edit mysite.sql on your local machine, find and replace the test URL with the production URL
  6. Import mysite.sql into Production
  7. Copy all Wordpress files from your local machine to Production
  8. Verify all functionality in Production.

What You'll Need

  • Your Wordpress username/password
  • Your web hosting provider (e.g. Dreamhost) username/password
  • (if migrating between two hosted sites) your database information from wp-config-php

NOTE: Throughout the article, the word test will be used for the testing environment or your localhost environment with the URL localhost. The word local machine will be any intermediate step taken to modify files in the interim. The word production will be used for the production environment with the fictitious url www.mysite.org.

Full Wordpress Migration Procedure

Export Test DB

  1. Log in to MAMP (localhost) or cPanel (remote).
  2. Access phpMyAdmin using the username and password for your database. This information can be found in Test wp-config.php).

  3. Locate the database in use for your Wordpress site (herein called "siteDB").

  4. Select "siteDB" from the left.

  5. Select the Export tab at the top after selecting "siteDB".

  6. In the Export options, show all available options on the screen. Verify that you're using utf-8 encoding (if shown) and that your export will be sent to an SQL file saved to your local machine. Beyond this, all default options should be OK.

  7. Export the .sql file. (An sql file is a plain text file that serves as both a database backup and a format for importing into other SQL DBMS environments.)

  8. Save this file in a secure place.

  9. Save a duplicate of this file on your local machine.

Duplicate/backup the Test Wordpress Folder

This is pretty self-explanatory. You'll want a full backup of all files associated with your Wordpress site.

  1. Duplicate the entire Wordpress structure starting from the root of the Test site folder.
  2. Save this folder in a secure place.
  3. (optional) Make a ZIP file of the folder. This ensures you have a non-editable backup.
  4. Save a duplicate of this folder on your local machine to prepare for the migration.

Set up a new database in Production

This is typically the first step of installing Wordpress on your own server for manual installations.

  1. Open cPanel in Production
  2. Find the icon for MySQL databases and create a new database.

  3. Record all information generated during this process.

    You'll need the following:

    • username
    • password

    • hostname (typically localhost, but make a note of the full database name)

    • database name

This information will be utilized to edit your wp-config.php file in the next step.

Edit wp-config.php on your local machine

  1. Find the wp-config.php file on your local machine. The file will be in the root folder of your site backup.
  2. Open wp-config.php in your favorite text editor.

  3. Find the entries corresponding to the information recorded in the previous step.

  4. Change username, password, hostname (if other than localhost), and database name.

  5. Save all changes to this file on your local machine.

Edit mysite.sql on your local machine

  • Open mysite.sql in TextWrangler, Sublime Text, Brackets, or another plain text editor. !!Do not edit this in any type of rich text editor!!
  • Find & Replace the values in the wp_options statement in the SQL file from http://localhost to http://www.mysite.org.

  • (recommended) You should also search for localhost and replace each instance with www.mysite.org. BE VERY CAREFUL! Only change information that needs to be changed. As a general rule for Find and Replace, start with the largest unique chunk of data and reduce the options down to the smallest unique chunk, being careful not to edit any content that is vital to the site.

  • By following this procedure rather than editing the site in production, you save a step and you ensure that all plugins work and that all image links remain intact.

Import the edited mysite.sql to Production

  1. Log in to the production database.
  2. Select the new database from the list of databases.
  3. Find the Import tab.
  4. Click "Import", select your local file from the dialog box, and click "Go."
  5. Verify that all tables are imported. To double-check, open up wp_options to see whether the site URL record is correct.

Copy all Wordpress files from your local machine to Production

Be sure that your Wordpress index.php file is at the root of the folder for your website. (You should not be installing into a subfolder of your domain unless you're making a deliberate choice to install into a subfolder.)

Make sure that your edited wp-config.php file uses the information for the production site.

Verify all functionality in Production

FAQ

Additional Resources

Common Wordpress Scenarios