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
- Setup the Windows Azure development environment
- Setup the Windows Azure SDK for PHP
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 Multisite optimized to run on Windows Azure. Though this article contains the steps needed to setup the multisite configuration it is recommended that you read the article on the WordPress Codex site to completely familiarize yourself with what is happening behind the scenes.`
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
- Setup a database that WordPress can write to.
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:
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 if you would like.
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.
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 in the form of firstname.lastname@example.org
-DB_PASSWORD - Password of user with access to the database
-DB_HOST - Hostname of database. This should be a fully qualified domain name.
-WP_ALLOW_MULTISITE - Set to true to allow WordPress to operate in multisite mode
-SUBDOMAIN_INSTALL - Optional, set to true if running WordPress Multisite with sub-domains. If you intend on using sub-directories for your blog network do not use this parameter.
-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.
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 -WP_ALLOW_MULTISITE -sync_key **** -sync_account ****
Running the WordPress scaffold may take several minutes. There are several critical operations happening:
- A WordPress archive is downloaded from http://wordpress.org and unpacked into the project directory
- The WordPress database abstraction plugin for SQL Azure is downloaded and added to the WordPress project files
- The Windows Azure Storage plugin for WordPress is downloaded and added to the WordPress project files
- WordPress is configured to work with Windows Azure services
- The Windows Azure service configuration file is setup
Open C:\temp\WordPress in a file browser and you should see the following files:
The WordPress files are located inside of the WebRole folder.
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 extension 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:
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.
Setup the Multisite network
At this point your WordPress install is still setup as a single stand alone blog. The next step is to choose the type of network setup and make a couple configuration changes. To start navigate to the Tools menu and choose Network Setup.
Network Setup using sub-directories
Choose the subdirectories radio button. The ; Network Title and Admin E-mail Address will be filled in automatically based on information submitted when you setup WordPress. If you would like to make changes you can do so now. When you are done click the Install button.
Next you will be taken to a page asking you to alter setting in wp-config.php and the .htaccess file. Windows Azure uses IIS, IIS uses a Web.config file instead of a .htaccess file. The correct Web.config file was created for you when you ran the scaffolder. Instead of editing the wp-config.php file you will edit the service configuration file through the portal.
Edit the service configuration through the portal
The wp-config.php file in the WordPress scaffold reads configuration from the Windows Azure deployment service configuration. The following steps will need to be completed in order to finalize the network setup of your WordPress Multisite installation.
- Login to the Windows Azure Portal
- Choose your hosted service, click on it
- Click Configure on the toolbar
- A dialog will pop up containing your service configuration.
Find the configuration options specified on the WordPress Network
Setup page and set their corresponding values in the service
configuration. When you are finished click OK.
Note: You $base is also listed in the service configuration.
- It will take a few moments for your configuration information to refresh, then your WordPress Multisite setup will be complete.
You may need to logout of WordPress and log back in before you see the Network Admin panel.
Configure the Windows Azure Storage plugin
The very last step to complete in order to fully take advantage of the power of Windows Azure is 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.
Note: The Windows Azure Storage plugin was built for a single WordPress site and therefore at the current time it must be configured on a per site basis.
Login to your WordPress administration backend and navigate to Plugins. Click Activate on the Windows Azure Storage for WordPress plugin.
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.
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!
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