Getting Started
This write-up is a guide for migrating a WordPress site from a local to a remote server, as if you were going from a local development environment to a remote environment on a hosting service. It is based on phpMyAdmin in a Windows environment.
- A database and user will need to exist before migrating from one server to another occurs.
- If it is a new install, create an empty database.
- It is a bit easier if the database name and the login information (username and password) is the same across both databases. If there is variation, the wp-config.php file will need to be updated to match the installation.
- Add a user to the new database from the remote phpMyAdmin panel.
- Usernames and passwords will be needed for the local and remote WordPress login, and the hosting service login.
- Replace the wp-content folder on the remote server with the newer files from the local directory. If it is just the theme that is changing, then you do not need to re-copy the whole directory – just the theme. This is typically done using FTP or if you use a service like Beanstalk for a development environment, there is a manual deployment option.
- Go to the local phpMyAdmin and export the local database (select database and then the Export option in the dropdown below the table). A sql file is created.
- Go into phpMyAdmin and import the sql file or paste the code into the sql window and select Go. The database must exist for this to work (see step 1).
- The paths need to be updated in the remote server database. This is done through sql commands.
- Copy the code below into a text editor:UPDATE wp_posts SET guid = replace(guid,`http://localhost/LocalSite/`,`http://www.RemoteSite.com/`);
UPDATE wp_posts SET post_content = replace(post_content, `http://localhost/LocalSite/`,`http://www.RemoteSite.com/`);
UPDATE wp_postmeta SET meta_value = replace(meta_value, `http://localhost/LocalSite/`,`http://www.RemoteSite.com/`);
UPDATE wp_options SET option_value = replace(option_value, `http://localhost/LocalSite/`,`D`) WHERE option_name = `home` OR option_name = `siteurl`; - Replace `http://localhost/LocalSite/` with the path to your local site.
- Replace `http://www.RemoteSite.com/` with the path to your remote site.
- Copy and paste the new code into the remote database SQL area and select Go.
- Copy the code below into a text editor:
This completes the migration. To go the other direction, just reverse the process. Given below are some troubleshooting tips.
Trouble Shooting
- Site is not styled or working correctly, but it appears.
- This may be due to the ftp program not copying the subdirectories of your theme.
- Go to your WordPress settings and make sure your site URL is correct, and update your permalinks.
- Blank screen. Recopy the whole site over.
- Still not working? Check these things:
- Check the database table for options and check that the url and home are correct.
- Make sure that wp-config matches the database name/username/password of the server.
- Make sure the htaccess file is correct for the hosting service.
- Look at the WordPress codex for potential solutions: Moving WordPress
Tips
- It is a good idea to use a different table prefix than WordPress default of wp. If they are different, then the above migration script will need to be updated with the correct prefix for wp_posts, wp_postmeta, and wp_options.
- When I initially setup the sites, I create a directory where I keep the migration and configuration scripts. Each file is clearly named. For example, local_to_remote_sitename.sql. In there is also a copy of the wp-content.php files.