How to add a custom domain name to a Windows Azure website

In my last blog post, I talked about migrating from a web host to Windows Azure. One of the remaining cleanup tasks was to point the domain name from something like louiebao-blog.azurewebsites.net to louiebao.net. The actual steps may be slightly different depends on who your domain registrar is but the general idea should remain the same. I am using DNSimple so I will be showing you screen shots from them.

Add a service for Windows Azure

After logging in to DNSimple, click on the desired domain name, goto “Add or edit services”, find Windows Azure and click on Add. Once presented with the “Setup Windows Azure Service” screen, enter the subdomain for your Azure site. This is the part before .azurewebsite.net, in my case louiebao-blog.

add_a_service_for_windows_azure

After adding the service, you will see a few new DNS records under the Windows Azure service. Note the A record isn’t there as DNSimple doesn’t know the IP address at this point, you will need to create it in a later step.

windows_azure_dns_records

Add the custom domain in Windows Azure

In Windows Azure’s mangement portal, goto the “Manage custom domains” dialog and enter the custom domain name, in my case louiebao.net. At this point, the awverify.louiebao.net CNAME record created in the previous step should be in action. Once Azure verifies that you own the domain, you will be able to add the domain name to the list.

Once this step is done, you can optionally remove the CNAME awverify record as it has no further use to us.

azure_manage_domains

Add an A record in DNSimple

Take the IP address from the “Manage custom domains” dialog and create a DNS A record with it in DNSimple.

dns_a_record

Remove DNS records from the old host

Go back to your old host and remove the now obsolete DNS records.

Wait for a hour or two or even longer

I am not joking as with DNS changes certain things just take a long time to refresh. I am not an expert on DNS but as long as your configurations are correct, it will work eventually. For the impatient ones, you can just go to the next step and keep checking on the status.

Check

I used http://www.digwebinterface.com/ to make sure the domain name can be successfully resolved to the desired IP address.

digwebinterface

Now my blog can be accessed from louiebao.net as well as louiebao-blog.azurewebsites.net. In case you are wondering, the default Azure domain name louiebao-blog.azurewebsites.net cannot be removed as far as I know.

One more thing

I quickly realised that I have missed a step after publishing this post. The WordPress settings are still pointing to louiebao-blog.azurewebsites.net and need to be updated as well.

wordpress_settings wordpress_settings_home

How to migrate a WordPress blog to Windows Azure

Just recently I have migrated this WordPress blog to Windows Azure. I am actually writing this post on the new platform. I have learnt a few lessons along the way and it is always a good idea to document them while everything is still fresh in my head.

Like doing anything for the first time, I started by searching for How To articles on the web. One frustrating thing I found was that there were a lot of out of date info around and after following a few step by step guides to no success, I eventually gave up and decided to go on my own.

After failing a few attempts, I stopped following other people’s instructions and started thinking. What is the most important content I care about? The answer was obvious, the blog posts. Do I care about themes, plugins and comments, etc? Yes but they are not critical. At a bare minimum, I would be content if only the blog posts were migrated across. In that case, I just needed to backup and restore the WordPress database then. Once I realised what I needed to achieve, the migration path became much clearer. Well that was the initial thinking but nonetheless, the path was more or less clear. What I found later was that a straight backup and restore would not have worked as the new environment was not empty, there was already data in the database.

Now I will cut to the chase and describe what I did step by step.

1. Install plugin to work with WordPress’s MySQL database

The plugin I used was called Adminer (formerly phpMinAdmin). I simply went to Plugins -> Add New -> Searched for Adminer -> Install -> Activate.

2. Decide on tables on export

Goto Tools -> Adminer -> Start Adminer inside

Once in Adminer, I was presented with 11 tables, the trick was to work out which tables I needed to export.

wp_options
I didn’t need to migrate this table because the new WordPress installation on Windows Azure contained all my options already and I could go back and match the settings manually anyway.

wp_users, wp_usermeta
Since this is my personal blog, I am the only user I care about, so no need to migrate this table either because I was already a user in the new environment. The ID of my users in both the old and the new databases were the same and this could be very handy during migrations.

wp_posts, wp_postmeta
These tables looked important, I definitely wanted to migrate them.

wp_terms, wp_term_relationships, wp_term_taxonomy
Yep, I also wanted to retain the categories.

wp_comments, wp_commentmeta
I decided not to bother with comments.

wp_links
The table was empty (later found out it was deprecated).

3. Export

Clicked on Export from the panel on the left and selected the following options

Output: save
Format: SQL
Database: <BLANK>
Tables: <BLANK>
Data: INSERT

Before exporting, made sure I ticked wp_postmeta, wp_posts, wp_terms, wp_term_relationships and wp_term_taxonomy tables.

4. Edit the exported SQL file

Once I had exported the tables, I started to inspect the SQL file. There were links to the old site littered across the file. I simply did a search and replace. (For example, from www.oldsite.com/blog to www.newsite.com)

5. Import into the new database

I then went into Adminer on the Windows Azure side and imported the SQL file. No errors. All good.

6. Check

Opened up the new site and it was a relief seeing all the old blog posts.

7. Publish a new blog post

If you are reading this, that means I have successfully migrated the blog from my old host to Azure. At least the main part.

8. What’s next?

There is still a bit of cleaning up to do as all those images and files from the old site also need to be moved to the new site. But that’s for another day. Stay tuned.