(Note: this may not be necessary on newer version of WordPress. Goto: Settings->General)

So you’ve hosted your WordPress app on PagodaBox, perhaps you’ve installed it manually or used the provided quick-start, and things are going great. You’re loving the smooth development process and version controlled deployment, and having a lot of fun at the same time. But then you decide you want to rename your app, and disaster strikes. After the transaction completes you try to access your blog and find that the page’s CSS isn’t loading, and neither are the images and attachments in your posts. Redeploys have no effect, and you soon begin to cry because you don’t have an XML back-up to rebuild your, now, busted app.

Well, fear not. All is not lost; you have the tools at your disposal to fix this. So take a deep breath, pour yourself a glass of orange-juice, and let’s get your app working again.

Why did it break?

When you set up and use WordPress it adds entries to the database with absolute referenced URLs which match your site’s URL when you set it up. Preforming an app rename in PagodaBox does not update these, and now WordPress is lost and confused. It keeps looking for things where they were recorded to exist, but cannot seem to locate them, and you end up with a completely messed up WordPress site.

How to fix it

So what you’ll need to do is fix these rows in the database. To do this, you’ll need to access your database component directly and run some SQL update statements. In order to access your database component you will need to establish a tunnel to your component (PagodaBox has a helpful blog post which shows you how to do this).

Using your MySQL client (MySQL Workbench, the CLI client, etc.) establish a connection your database through the tunnel. As explained in the previously linked blog post, you will connect to the host name and port shown when you open the tunnel, and use the credentials for the database which you can find in your PagodaBox dashboard.

First we need to update two rows in the wp_options table. These essentially tell your blog what it’s URL is and will fix most of the aesthetic and some of the navigational problems. The following SQL statements will perform this update:

USE `wp-db`;
SET @new_url = 'http://my-domain.com';
UPDATE wp_options
	SET option_value = @new_url
	WHERE option_name = 'siteurl' 
		OR option_name = 'home';

Now there will still be an issue with the URLs for the content in your blog. This will be fixed by running an update on the guid column in the wp_posts table:

USE `wp-db`;
SET @old_url = 'http://my-app.pagodabox.com';
SET @new_url = 'http://my-domain.com';
UPDATE wp_posts
SET guid = REPLACE(
	  guid
	, @old_url
	, @new_url
	);

Now lastly if you have any attachments in your posts, these need to be updated. The following statement will fix all the links in your posts’ content:

USE `wp-db`;
SET @old_url = 'http://tech.0x783czar.com';
SET @new_url = 'http://my-domain.com';
UPDATE wp_posts
SET post_content = REPLACE(
	  post_content
	, @old_url
	, @new_url
	)
	WHERE post_type = 'post';

These steps can also be useful when you add a DNS alias to your app so that your domain points to it. Performing these updates will keep the URLs uniform on your site.

Be sure to run these in transactions or with save points so you can easily rollback the changes in case something doesn’t work. Hopefully this was helpful!