Moving/copying a WordPress site and domain name related file and database changes

If you move a WordPress installation to a new server, for example make a local develoment, copy, you need to fiddle with the database in order to make the site function correctly.

WordPress has a (flawed) design choice made where it stores full URLs, including domain name, in the database data and thus simply dumping and copying over the database does not help. It would be possible to do this without storing full URLs in the database, as other CMSs (Plone) can do it using a method called virtual host monster (special URL rewrite/proxy patterns in Apache configuration files). This prevents you copying the WordPress installation from the production server to your local computer and doing the development against localhost.

Here are some notes what tables and files you need update and how for WordPress Network (multisite) installations where the multisite method is folder based.

You need to be familiar with UNIX shell.

First dump database from the remote server (ssh + mysqldump instructions) and then rsync WordPress files (rsync instructions).

1. wp-config.php

define('DOMAIN_CURRENT_SITE', 'site.com' );
define('WP_HOME','http://site.com');
define('WP_SITEURL','http://site.com');
define('RELOCATE',true);

Note down username and password for MySQL database from wp-config.php. You are going to need them when running the next commands from MySQL shell.

2. wp_options table

Options storage for the primary site.

update wp_options set option_value="http://site.com" where option_name="home";
update wp_options set option_value="http://site.com" where option_name="siteurl";

3. wp_blogs and wp_sites tables

Here are stored multisite installations of WordPress.

update wp_site set domain="site.com";
update wp_blogs set domain="site.com";

More info in the previous blog post.

 Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

Leave a Reply

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