Enabling additional WordPress Azure websites to reuse existing MySQL database

It’s super simple to create your first WordPress blog using Microsoft Azure Websites Gallery. Getting this all up and running is extremely fast. I’ve uploaded a short video and blog post showing how to setup up a WordPress site in Azure in only a couple of minutes.

But what if you want to create a second WordPress Azure website while reusing your existing MySQL database from the first one?

AZURE_WP201_create-multiple-wordpress-websites-using-existing-mysql-database

Initially when I load up the ‘*.azure-websites.net’ URL I just get a blank page (which is PHP’s quiet way of letting you know something needs fixed). When you reuse the existing MySQL database then you going to need to tweak one setting in the WordPress configuration file (wp-config.php). To modify this config file you will need to grab your FTP settings in your Azure website dashboard.

AZURE_WP202_azure-websites-dashboard-ftp-upload-settings

Download the publish profile to get your FTP username and password. Open this file in an XML text editor to locate the ‘userName’ and ‘userPass’ values which are located just after the ‘ftpPassiveMode’ attribute.

Once you FTP in, navigate to ‘site/wwwroot/’ and edit the wp-config.php file (you may wish to download a backup first). Then change the ‘table_prefix’ value (line no. 62) from:

to something like:

You should now be able to navigate to your website URL ‘*.azure-websites.net/wp-admin/’ to complete the WordPress setup.

Also, if you want to see what this looks like in your database just open up a MySQL client to check the new WordPress tables added using the connection settings available in your Azure Websites dashboard.

AZURE_WP202_azure-portal-dashboard-connection-settings

Setting up a WordPress website with Azure

  1. Start an Azure trial or sign-in into your Microsoft Azure management portal.
  2. Select WEB SITES and choose NEW > WEB SITE > FROM GALLERY
    AZURE_WP01-Azure-Website-Gallery-Wordpress
  3. Select BLOGS > WordPress
    AZURE_WP02-Azure-Apps-Wordpress
  4. Enter unique site URL at *.azurewebsites.net (you will be able to add your own domain name later). Choose MySQL database option and preferred region. Deployment Settings are optional and can be skipped.
    AZURE_WP03-Azure-Wordpress
  5. Setup your WordPress site by visiting your Azure Website’s URL http://*.azurewebsites.net in your browser.
  6. To setup custom domain name URL you will have to upscale from FREE to STANDARD. In your website menu select SCALE > STANDARD.
    AZURE_WP04-Azure-Wordpress-Custom-Domain-Name-Scale-Standard
  7. Select CONFIGURE > domain names > manage domains
    AZURE_WP05-Azure-Wordpress-Manage-Domains
  8. Enter your custom URL. You will also need to make a note of the CNAME record awverify.www.*.azurewebsites.net to verify ownership and the IP ADDRESS provided to update your DNS A-Record.
    AZURE_WP06-Azure-Wordpress-Manage-Custom-Domains-IP-Address-
  9. Go to your domain registrar control panel to modify the domain’s DNS Records.
    Add the CNAME record awverify.www.*.azurewebsites.net
    (Note: some registrars require Canonical names to have an extra ‘.’ at the end)

    AZURE_WP07-DNS-Records-Add-CNAME
  10. You will also need to remove any existing A Records and replace with a new A Record pointing to your Azure Website’s IP Address.
    AZURE_WP07-DNS-Records-ARecord
    AZURE_WP07-DNS-Records-Updated
  11. Once your DNS changes are in sync (usually 1-2 hours), you can update the domain settings in your Azure Website’s WordPress control panel to match your domain.
    AZURE_WP08-Azure-Update-Wordpress-Site-Address-URL
    AZURE_WP08-Azure-Updated-Wordpress-Site-Address-URL
  12. Finally, I would activate Settings > Permalinks using one of the presets or a custom structure. This enables a number of benefits including SEO friendly URLs so your keywords can appear in the URL address bar. Also advanced users can navigate using your URL address. Tip: for huge blogs it maybe advisable to start with a number (like %year% or %post_id%) for speed.
    AZURE_WP09-Azure-Wordpress-SEO-Friendly-URLs-Permalinks
  13. Just one more thing… It’s probably a good idea to backup your WordPress website so you can rollback if a WordPress update ever goes wrong. Azure BACKUPS is a new feature which automatically backs up to a STORAGE data service. When creating a new Storage component I would select a different region and set replication to ‘Locally Redundant’ which is the most cost effective option.
    AZURE_WP10-Azure-Backups

Thanks @plankytronixx for the Azure Websites bootcamp!

UPDATE: I also found this post very helpful in setting up advanced DNS settings for Azure Websites.