Migrating/copy WordPress site to new sub/domain by hand

From time to there is need to migrate or make a working copy of site that works on wordpress. There are many plugins for that but I will show you the manual way if you want to do it without 3rd party help.

I assume that you are able to connect to mysql via cli or with myphpadmin, and you are able to tell which database you use for you wordpress (wp_config.php). So lets get started

# if you using cli
mysql -u root -p databasename ;or; mysql

UPDATE wp_options SET option_value = replace(option_value, 'http://oldurl', 'http://newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://oldurl','http://newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://oldurl', 'http://newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://oldurl','http://newurl');

Just remember if you want to copy db and use new updated one edit wp-config.php to reflect those changes:

/** MySQL database name */
define('DB_NAME', 'databasename');

/** MySQL database username */

define('DB_USER', 'username');

/** MySQL database password */

define('DB_PASSWORD', 'password');

/** MySQL hostname */
define('DB_HOST', 'localhost');

Leave a Reply

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