Moving Blog to Different Domain

A WordPress blog is a combination of three parts:

  • Web Hosting Control Panel.  This is only an issue if you wish to use the control panel provided by your web hosting company to install and update your WordPress installation.
  • Files on the domain (WordPress, configuration, plugins, templates, image uploads, etc.)
  • MySQL database with several tables.  Each starts with a $table_prefix variable (found in wp-config.php), with a default of “wp_”.

I have been keeping a blog dealing with photography. I initially put the blog under subdomain www.photo.franzkelsch.com. I decided to use get a new domain for my photography work and I wanted to move my blog to a subdomain there using www.blog.kelschphoto.com.

Since I was self-hosting using the WordPress blog publishing system on my own web hosting server with my own registered domain name moving the blog was not as simple as just exporting and reimporting the MySQL database. There are some steps that should be done to ensure the proper migration and no breaking links.  I also wanted to have my web hosting company install the new blog so I could upgrade it from their control panel.

Here are the steps I used to move my blog.

Backup Old Blog First

  • I made sure my old blog was running the latest WordPress software
  • I used FTP to download download all files from my old blog
  • I used the admin panel in my old WordPress blog to export the database.

Install New Blog

  • I first created a new WordPress blog in the subdomain using a brand new MySQL database table, including setting up user accounts.
  • From the FTP backup, I restored to the new location, the themes and plugins under “\ wp-content”  I has manually added to my old blog.
  • I activated the plugins and changed the theme to match.

Fixing the New Installation

  • Using the WordPress admin panel in the new blog, I selected to import the WordPress export from the old blog.  I checked the blog so it would find the uploads on the old blog and include them in the new blog.
  • To fix the links inside the blog I used phpMyAdmin on the newly imported database and issued these commands.

To update WordPress options with the new blog location:

These steps are not needed if you follow the new export/import functions show above
——————————————

UPDATE wp_table_prefix_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

To fix URLs of the WordPress posts and pages:

UPDATE wp_table_prefix_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

——————————————

To update any internally links within blog posts or pages with absolute URLs first find the table_prefix in the wp-config.php file so you know the name of you tables.  Then do this SQL querry update

UPDATE wp_table_prefix_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

  • I then tested the new blog and when I determined all was working, I deleted the old blog.

Changing Database Name

I had started to accumulate so many blogs that the casual type names I had given to the databases got out of hand.  I decided to change the names of the database to be similar to the domain name where I was hosting the WordPress blog.  So if the blog is at sports.franzkelsch.com I would want to use a database that shows the type of data it contains and the domain it is associated with such as wp_sports_franzkelsch .  That would be enough for me to quickly know it is a WordPress blog that is hosted at sports.franzkelsch.com.  I am currently hosting my sites at Dreamhost and I can not just rename the database since the blog is setup to use a particular database.

Matters are more complicated when I wanted to use the control panel on dreamhost.com (where I host my domains).  If it were not for this, I could simple create a new MySQL database and import to it the contents of the old database, then edit the wp-confg.php file to show the new database name.  But to keep the right settings in my Dreamhost control panel, so I could use it to update the WordPress files in the future, I had to follow:

  • Backup the MySQL database (Use phpMyAdmin or some other program)
  • Backup all the files in the domain/folder
  • Use the control panel to remove the WordPress installation.  You must do this before deleting the old MySQL database.
  • Either wait for the hosting company to delete the files or use FTP to delete them from the domain/folder
  • Create a new WordPress blog using the new MySQL database name
  • Manually delete the files that were added to the domain/folder by this installation.
  • Restore your MySQL backup to the new database
  • Edit the wp-config.php file to change the name of the data base in your backup files
  • Restore the files to the domain/folder
  • Check all is working
  • Delete the old MySQL database
  • Do a new WordPress install using your web hosting control panel.
  • Restore the files you backed up since the new install will be missing all your uploads.
  • Restore the MySQL database backup since the new install of WordPress will overwrite this
  • Go to the Site Admin, select Settings, then Permalinks.  Click Save to recreate the permalinks.
  • Remove the old MySQL database

That will get things synced in your webhosting control panel. Not sure it is worth all the effort, however.