Changing the host name in a WordPress app


This entry is going to cover how to change your hostname entries in a WordPress app. A small bit of this entry will be pagodabox specific, but I will point that out along the way. Also I should point out that this defiantly falls into the category of ‘ blogging-about-blogging ‘ and I almost did not write this because of that simple fact. However I expect to be reading this in the future. So I decided to write the entry.

Overview

When you use WordPress its dbms schema will embed your hostname into the dbms in several locations. This for the most part is not too troublesome until you decide to move your app to another machine, or change your hostname. The later usually occurs when you decide that your blog is ready for prime time, and it’s time to buy that fancy domain name.

This will guide you through the steps of making the change to those entries.

  1. Log into your dbms
  2. change the home and site_url options in the wp_options table
  3. change the guid values in the wp_posts table
  4. update the post_content in the wp_posts table

1: Log into your DBMS

Here, I am are going to be a bit pagodabox specific. Follow this guide on how to create an ssh tunnel into your dbms . You will be using the pagoda terminal client and you will be creating a ssh tunnel to your dbms.

$ pagoda -a  tunnel -c 
# Component id example db1

Once you have your ssh tunnel created, you should have a port [3307] forwarded to your local machine. Now you simply need to log into your mysql database like it was a local database on your machine.

$ mysql --host 127.0.0.1 -P 3307 --user  --database wp-db  -p

2:3:4: Change dbms contents

Alright, you are now ready to do the dbms content modifications.

-- First query what you have
SELECT * from wp_options where option_name LIKE 'hom%';
SELECT * from wp_options where option_name LIKE 'site%';
 
-- Next update the old host 'http://sleepy-stacia-02.gopagoda.com' with your hostname
-- with your hostname 'http://myniftyhostname.com'
UPDATE wp_options SET option_value = replace(option_value, 'http://sleepy-stacia-02.gopagoda.com', 'http://myniftyhostname.com') WHERE option_name = 'home' OR option_name = 'siteurl';
 
-- Peek at the guid values
SELECT guid FROM wp_posts;
 
-- Update the guid values
UPDATE wp_posts SET guid = REPLACE (guid, 'http://sleepy-stacia-02.gopagoda.com', 'http://myniftyhostname.com');
 
-- Peek at the post_content ( warning: could be alot of data..., and if so.. no need to peek)
SELECT post_content FROM wp_posts;
 
-- update the wp_posts data
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://sleepy-stacia-02.gopagoda.com', 'http://myniftyhostname.com');

You are now done, enjoy the fact that your uri’s stay the same while clicking through your site.

Reference: