Moving WordPress sites from host to host isn’t as difficult as you may think. Following these simple steps will help guide you through the entire process: copy/move site files, copy/move the database, and most importantly update your database/table values with this special MySQL query.
Moving WordPress sites from host to host isn’t as difficult as you may think. I tend to take a straight-forward and direct approach to transfer WordPress to a new host/environment. I copy and move all the site files as well as the database/tables. I then update several database/table values to ensure that the moved WordPress site will work properly.
The Basic Steps
- Copy WordPress site files
- Copy WordPress database/tables (duplicate them, export/import)
- Migrate WordPress site files to the new host
- Migrate WordPress database/tables to the new host
- Update old WordPress database/table values (this step is very important, see video)
Copy and Migrate WordPress Site Files
You will need access to your current site files, typically you will do this through FTP. Login and begin to copy your site files locally (on to your hard drive). Once you have a backup of your site files, you will want to copy them to the web root directory on your new host.
Copy and Migrate WordPress Database/Tables
In this step you will need access to your database. Most hosts/providers will have a control panel and/or access to phpMyAdmin. If you are already familiar with this step, you may be using Navicat or MySQL Workbench to do your copying.
Essentially you will want to dump (export/backup) your entire WordPress database. After exporting your database, you will need to import it into your new host. This step may require that you setup a new MySQL database and database username/password (your hosting provider will have a control panel to do this). To import you will most likely be using a similar tool like phpMyAdmin, Navicat or MySQL Workbench.
Note: Remember to update your
wp-config.php file with your new database information.
Updating Old WordPress Database/Table Values
Tip Select 720 HD mode and watch it fullscreen or click the YouTube button to watch it on YouTube.
This step is very important, simply moving your database and linking it up to WordPress isn’t enough. Your old database/table (export/backup) will have all its old values: old host names and urls. To update these I run the followng MySQL query:
SET @from_host = 'www.oldhost.com'; SET @to_host = 'www.newhost.com'; UPDATE `wp_options` SET `option_value` = REPLACE(`option_value`, @from_host, @to_host); UPDATE `wp_posts` SET `guid` = REPLACE(`guid`, @from_host, @to_host); UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`, @from_host, @to_host); UPDATE `wp_comments` SET `comment_author_url` = REPLACE(`comment_author_url`, @from_host, @to_host); UPDATE `wp_comments` SET `comment_content` = REPLACE(`comment_content`, @from_host, @to_host); UPDATE `wp_links` SET `link_url` = REPLACE(`link_url`, @from_host, @to_host); UPDATE `wp_postmeta` SET `meta_value` = REPLACE(`meta_value`, @from_host, @to_host); UPDATE `wp_usermeta` SET `meta_value` = REPLACE(`meta_value`, @from_host, @to_host); UPDATE `wp_commentmeta` SET `meta_value` = REPLACE(`meta_value`, @from_host, @to_host);
This will essentially do a search and replace of the old host/domain name to the new one. Change the two variables at the top, before you run the query (
Some WordPress installations will have plugins, that when transfered will prevent a site from properly working, until that plugin is deactivated and then reactivated. Additionally certain plugins have saved values in the
wp_options table, these values may be old site directory paths, which are likely to break on a new host. A quick way of dealing with this is to deactivate all your plugins. You can do this by running the following SQL query:
DELETE FROM `wp_options` WHERE `option_name` = 'active_plugins';
As you reactivate, each plugin should reinitialize with correct directory paths and other values.
Warning some plugins may reset to their original default values, however some will continue to use their existing values.