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.
- 1 The Basic Procedure
- 2 What You'll Need
- 3 Full Wordpress Migration Procedure
- 3.1 Export Test DB
- 3.2 Duplicate/backup the Test Wordpress Folder
- 3.3 Set up a new database in Production
- 3.4 Edit wp-config.php on your local machine
- 3.5 Edit mysite.sql on your local machine
- 3.6 Import the edited mysite.sql to Production
- 3.7 Copy all Wordpress files from your local machine to Production
- 3.8 Verify all functionality in Production
- 4 FAQ
- 5 Additional Resources
The Basic Procedure
The basic Wordpress migration process follows a simple procedure:
- Export Test DB as a .sql file (for this tutorial, "mysite.sql")
- Duplicate/backup the Test Wordpress folder on your local machine
- Set up a new DB in Production
- Edit wp-config.php on your local machine, add new database information
- Edit mysite.sql on your local machine, find and replace the test URL with the production URL
- Import mysite.sql into Production
- Copy all Wordpress files from your local machine to Production
- 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
- Log in to MAMP (localhost) or cPanel (remote).
Access phpMyAdmin using the username and password for your database. This information can be found in Test wp-config.php).
Locate the database in use for your Wordpress site (herein called "siteDB").
Select "siteDB" from the left.
Select the Export tab at the top after selecting "siteDB".
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.
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.)
Save this file in a secure place.
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.
- Duplicate the entire Wordpress structure starting from the root of the Test site folder.
- Save this folder in a secure place.
- (optional) Make a ZIP file of the folder. This ensures you have a non-editable backup.
- 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.
- Open cPanel in Production
Find the icon for MySQL databases and create a new database.
Record all information generated during this process.
You'll need the following:
hostname (typically localhost, but make a note of the full 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
- Find the wp-config.php file on your local machine. The file will be in the root folder of your site backup.
Open wp-config.php in your favorite text editor.
Find the entries corresponding to the information recorded in the previous step.
Change username, password, hostname (if other than localhost), and database name.
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
- Log in to the production database.
- Select the new database from the list of databases.
- Find the Import tab.
- Click "Import", select your local file from the dialog box, and click "Go."
- 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.