CodingJohnson

05 November
0Comments

Deploying WordPress to Azure

I’ve been eager to do some public facing stuff with Azure since I’ve been doing work for clients recently that may not be public facing at all, or at least for some time - so I thought I’d take the time to migrate my blog from WordPress.com onto my private domain hosted on an Azure account.

It did take up a few evenings of researching how to get PHP onto Azure but it’s much easier than I thought - a few lessons learnt along the way were

  1. It’s not that well documented on the interwebs
  2. It’s actually easier than all those forum posts from 2009 make out

Prerequisites

You’ll need the following

  1. An Azure account
  2. Azure SDK
  3. PHP
  4. Azure SDK for PHP
  5. File System Durability Plugin
  6. WordPress on Azure scaffolding tool
  7. WordPress plugin for Azure storage

Setting Up Azure

I’ll assume you already know how to setup the Azure services, and if you don’t then it’s easy enough to find out how. The important thing is to mention which services you should have set up, if you’ve just signed up now and you’re ready to go, you’ll see me talk about the Azure Management interface

    1. Hosted Service
      1. For the hosting of the WordPress application
    2. (Blob) Storage Account
      1. For storing images and media
    3. SQL Database
      1. For storing blog data

It’s important that in each you take note of the data you enter, since some of this is needed for configuring your WordPress deployment to Azure.

Build Environment

The Azure SDK is best downloaded and installed using the Web Platform Installer since it takes care of most configuration and installation options.

The File System Durability Plugin synchronises files between your machine and Azure, this handy little tool can install anywhere and doesn’t need configuring.

PHP needs installing or dropping to a place of your choosing depending on the package you download, the important thing to note is that PHP may need adding to your machines “PATH” environment variables, but if that’s too much for you then just run the snippet below to have it available as a PATH variable during your logged on session. There’s also some oddities when using PHP with Windows, needs to have a “php.ini” at the root of the installation (there should be two template ini files available) and you’ll need to ensure that the line with extension=php_curl.dll is uncommented (i.e. remove the leading semi-colon)

The Azure SDK for PHP is just a bunch of tooling that can unpack pretty much anywhere, but like PHP above, it’s important that the bin folder in this package is available from the PATH variables since we’ll be using both applications from the command-line - so the snippet below will kill two birds with one stone and temporarily add PHP and Azure SDK for PHP folders to your PATH variables.

The WordPress on Azure scaffolding tool should contain a .phar file, although it may appear small for WordPress, this file is not some kind of pre-packaged WordPress installation, it’s just a configuration script to download and pre-configure WordPress for you, that’s the reason it’s called scaffolding. To make this work you’ll need to run some command-line snippets, but the WordPress on Azure scaffolding tool has a handy build.bat file hosted on their GitHub account that will do most of the work for you if you place the file in the same location as the .phar file.

After running it you should see a new build folder that contains a WordPress folder and a full and recent installation of WordPress, this is the copy of WordPress that we will eventually upload to Azure so this is copy you should ideally do development against locally and configure if you want to do any configuration/customisation locally.

Configuring the Build

The Azure project will have a configuration file named ServiceConfiguration.cscfg contained in the WordPress folder, there are primarily two sections to this file that need configuring

SQL Database Information

The SQL information at the top of the file is hopefully self-explanatory to complete and all these details can be obtained from the Azure Management portal when you were setting up the SQL Database. It’s important to note that where I’ve put servername is just the random portion of the Azure SQL Server name, for example vx30iu5d02

Azure Storage Information

The Azure Storage Information needs entering a bit furthering and specifically targets the FileSystemDurabilityPlugin we downloaded earlier, this needs the easily obtainable Azure Storage service name, and the slightly less easily obtainable Primary Access key which you can get from the Azure Management Portal when viewing the properties of the Azure Storage service. You’re looking for something like in the image below

Preparing the Deployment Package

Once all your configuration information has been entered you’re ready to instruct the Azure SDK to package your WordPress project, typically we can do this through the command-line but I prefer to stick the snippet below into a batch file and drop it in the build folder

After running the batch file you should see a new folder appear called package, this should contain the two files needed for a deploy to your Azure Hosted Service.

Deploying Your Package

This is a fairly trivial step, but does take some time to complete - you should also be aware that the Azure Management Portal will let you deploy to a Staging environment, or to a Production environment which is an incredibly useful feature.

If you deploy to the staging environment the portal will give you a temporary URL to access and test the deployment from, and if you need to upgrade it to a Production deployment you should go through the VIP context-menu option.

Congrats! If you navigate to your deployment URL you should now have a fully functional copy of WordPress on your Azure account and be presented with the beautiful default WordPress theme and one-time configuration screen.

If you wish to point your own domain at the WordPress installation then you will want to add a CNAME record to the DNS settings for your domain-name to point it at AzureAccountName.cloudapp.net - and don’t forget to update your WordPress settings!

 
No comments

Place your comment

You must be logged in to post a comment.