How to deploy WordPress using the Windows Azure SDK for PHP WordPress scaffold

Author: Ben Lobaugh <ben@lobaugh.net>

Date: Wednesday, August 24, 2011, 12:42:15 PM

Tags: Scenario, WordPress

Table of Contents

Note:This article pertains to the CodePlex SDK initially released late 2009. The Windows Azure team has since then released a newer version of the Azure SDK for PHP on Github. Please refer to the Windows Azure PHP Developer Center for documentation on this more recent version of the SDK.

Please stay tuned and come back here regularly as we are working on refreshing the tutorials to deliver up to date and useful content for our PHP developers.

;

Update (2011-12-19): Removed dependency on FileSystemDurabilityPlugin

Recommended Reading

Understanding Windows Azure

Pre-Requisites

Synopsis

This article will show you how to use the scaffolding features of the Windows Azure SDK for PHP and the WordPress scaffold to quickly deploy an instance of WordPress optimized to run on Windows Azure.

This article assumes you have a Windows Azure development environment already setup on your machine. If you have not setup the development environment yet please see the articles listed in the Pre-Requisite to get your Windows Azure development environment setup.

Internet access is required for the WordPress scaffold to download several core components.

Windows Azure service setup

Before you will be able to run WordPress on Windows Azure you need to setup the following services:

  • Hosted Service
  • Storage account
  • SQL Azure database

For more information on setting up these services see the following MSDN articles

Download the WordPress scaffold

A version of WordPress that is optimized to run on Windows Azure has been turned into a scaffold to allow for easy configuration and deployment to Windows Azure. The WordPress scaffold can be downloaded from:

https://github.com/Interop-Bridges/Windows-Azure-PHP-Scaffolders/tree/master/WordPress

The WordPress.phar file contains the packaged scaffold you need to run this tutorial. The WordPress folder contains the source of the scaffold which you can download and alter as need requires.

Place the WordPress.phar file into C:\temp for easy reference during the remainder of this article

Run the WordPress scaffold

When the WordPress scaffold is run the optimized version of WordPress will be built in a project location of your choosing, for this article we will be using C:\temp\WordPress.

Parameters

The WordPress scaffold requires several parameters when being run. The values of the given parameters will be used to populate the ServiceConfiguration.cscfg file.

-DB_NAME - Name of the database to store WordPress data in

-DB_USER - Username of user with access to the database. This will be of the form user@db_host

-DB_PASSWORD - Password of user with access to the database

-DB_HOST - Hostname of database. This should be the fully qualified domain name

-sync_account - Endpoint of Windows Azure Storage account. NOTE: Inside of this storage account you will need to create a public container called 'wpsync'

-sync_key - Access key of Windows Azure Storage account

Note: If you need to change the value of a parameter after running the scaffold you will not need to rerun the scaffold. Open the ServiceConfiguration.cscfg file for editing and you will see all the values you entered previously.

Additional Parameters

More parameters than those listed above are available in the WordPress scaffold. All additional parameters contain a default value that generally will not need to be changed. You can view all available parameters with the following command:

scaffolder help -s="C:\temp\WordPress.phar"

Create the project

The WordPress scaffold can be run with the following command:

scaffolder run -s="C:\temp\WordPress.phar" -out="C:\temp\WordPress" -DB_NAME **** -DB_USER ****@**** -DB_PASSWORD **** -DB_HOST ****.database.core.windows.net -sync_account **** -sync_key ****

Running the WordPress scaffold may take several minutes. There are several critical operations happening:

Open C:\temp\WordPress in a file browser and you should see the following files:

  • WebRole/
  • ServiceConfiguration.cscfg
  • ServiceDefinition.csdef

The WordPress files are located inside of the WebRole folder.

image

Using an existing WordPress codebase

If you already have an existing WordPress codebase and would like to move your files into the WordPress scaffold there is a new command line parameter that will allow you to import your existing source instead of downloading a new copy. To use it add the -source parameter, which will be similar to the following

-source path/to/WordPress

Customize WordPress

WordPress writes directly to the file system when themes and plugins are installed. This will work in Windows Azure, however changes written to the file system are not durable and will be erased when the instance is restarted or upgraded. Also the file system is not shared across instances so if there are multiple instances running on the same WordPress installation they will not know of any changes made to the file system by any other running instance. Therefore the proper method of adding themes and plugins is to do it now before it is packaged and uploaded.

If you desire to upgrade or add additional files later it is recommended that the files be added to the project files on the development machine and WordPress repackaged.

Custom php.ini settings

If you need to add or change custom settings in the php.ini file this scaffold has support for that. Open the WebRole directory and you will find a php directory. Inside of that directory is a php.ini file. Whatever settings exist in here are automatically added to the installed PHP's php.ini at runtime.

Additionally if you have extensions you would like to run they may be added to the ext folder and setup in the php.ini. All files in the ext folder are copied to the installed PHP's ext folder at runtime and will be available for use.

Package the WordPress project

When you are finished customizing your WordPress installation you will need to package the project to deploy. The following command will create the package:

package create -in="C:\temp\WordPress" -out="C:\temp" -dev=false

Deploy the WordPress package

You now need to deploy the package files to Windows Azure to get the WordPress site running. If you have not deployed a Windows Azure package see the following articles:

  • Deploy through the Portal
  • Deploy with the deployment tool

Finalize the WordPress installation

The final step is to visit the URL you chose when creating the Hosted Service which the WordPress package is deployed on. When you visit the URL you will be presented with the standard WordPress form to fill in the details about your site and initial login information.

image

image

image

image

;

Configure the Windows Azure Storage plugin

Finally you need to configure the Windows Azure Storage plugin. This plugin stores all your uploaded media files in blob storage. DO NOT SKIP THIS STEP! If you upload media files directly to the file system on your instance you will lose them when the role is recycled or updated.

Login to your WordPress administration backend and navigate to Plugins. Click Activate on the Windows Azure Storage for WordPress plugin.

image

After activation navigate to Settings > Windows Azure. This page will bring up the Windows Azure Storage configuration settings. You will need the name of your storage endpoint as well as your primary connection key.

image

After you click Save Changes you will need to specify the Default Storage Container and check the Use Windows Azure Storage when uploading via WordPress' upload tab checkbox to ensure all uploaded media files are transferred to durable blob storage.

You may now begin using your new WordPress installation to create content as you would any standalone WordPress install.

Congratulations on getting WordPress running on Windows Azure!

image

;

What happened to the FileSystemDurabilityPlugin?

The FileSystemDurabilityPlugin is a plugin for Windows Azure that was previously required to ensure the database conversion files were consistent across all running instances. With updates to the database abstraction plugin this is handled automatically for all instances. The FileSystemDurabilityPlugin is no longer required to ensure a solidly running WordPress installation on Windows Azure and has been removed from the scaffold to reduce complexity and remove a potential point of failure.

If your project requires the FileSystemDurabilityPlugin it can still be found on Github at https://github.com/Interop-Bridges/Windows-Azure-File-System-Durability-Plugin

 
blog comments powered by Disqus