Build and deploy a Windows Azure PHP application

Author: Ben Lobaugh <>

Date: Monday, August 8, 2011, 12:05:35 PM

Tags: Get Started

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.


Recommended Additional Reading


In this tutorial you will learn how to build a full Windows Azure PHP application. You will be guided from nothing all the way through the deployment phase when your application will be public.

You will need to ensure you have properly setup the Windows Azure development environment and the Windows Azure SDK for PHP. See links in the Pre-Requisites section for more information.

Sample files

Unlike other tutorials no sample files will be provided for this tutorial. All code needed will be contained within this document.

This tutorial will assume you are working out of the C:\temp\WindowsAzurePHPApp directory for all project files and commands.

Creating the Windows Azure PHP application base

Building a Windows Azure PHP application can be a complex process involving setting up the ServiceConfiguration.cscfg and ServiceDefinition.csdef files, as well as building scripts to install PHP and do any PHP customization you would like. Luckily the Windows Azure SDK for PHP provides a convenient scaffolding tool that will create a very basic Windows Azure PHP application structure for you. At the simplest this allows you to copy your project files in and immediately deploy, all the way to extreme customization, giving you control over virtually every aspect of your deployment. For the purposes of this tutorial a basic Windows Azure PHP application will suffice.

To create this basic Windows Azure PHP application, open a command prompt and run the following command:

scaffolder run -out="C:\temp\WindowsAzurePHPApp"

You may now navigate to C:\temp\WindowsAzurePHPApp where you should see a file layout similar to the following:


Right now you could package and deploy this application and it would install PHP on your Windows Azure deployment for you; however it would not be doing much else.

A breakdown of the structure is as follows:

  • PhpOnAzure.Web - This folder will be the document root of your application. All your application files go here
    • bin - Contains the startups scripts that install PHP and perform other miscellaneous functions when you deploy
    • php - Contains custom php.ini settings as well as any custom PHP extensions your application requires
    • resources - Contains miscellaneous files which support deploying your application
    • diagnostics.wadcfg - A basic diagnostics setup file. You can use this to track items such as CPU usage and network bandwidth
  • ServiceConfiguration.cscfg - Contains the Windows Azure configuration settings for your deployment. This file gets uploaded along with the final package
  • ServiceDefinition.csdef - Contains information about the setup of your deployment. This file is included in the final package that is uploaded to Windows Azure

This tutorial will not go into depth on the configuration files, however there will be a list of useful resources located at the end of this tutorial that will teach you more about these files.

Build the PHP application

Now comes the fun part, putting your PHP skills to use and building a shiny new application! For simplicity and ease you will be creating a simple PHP info page, but you will quickly see how easy it is to build a PHP application on top of the Windows Azure platform.

Inside the PhpOnAzure.Web folder create a new file named index.php and open it for editing. Add the following code and save the file.


Nothing fancy, but still a highly effective example.

Run the PHP application in the local development environment

Usually you will want to test your application before releasing it to production. There are two intermediate steps you can use to test before release; the local development environment, and the staging server. The staging server is available in the Windows Azure Portal and the process to utilize it is very similar to the production deployment. When you are satisfied with the way the staging application runs you are able to quickly switch from staging to production through the portal. We, however, are going to focus on the local development server in this tutorial.

The following steps will run your application in the local development server:

  • Open a command prompt
  • Run the command 'package create -in="C:\temp\WindowsAzurePHPApp" -out="C:\temp\WindowsAzurePHPApp\build" -dev=true'
  • Your application will begin building and in a few seconds the default web browser will open and you should see the output of phpinfo() similar to below


Run the PHP application on Windows Azure

To run any application on Windows Azure you need two files, a Windows Azure package and a ServiceConfiguration.cscfg. By slightly tweaking the previous command both files will be generated and can immediately be uploaded through the Windows Azure Portal.

  • Open a command prompt
  • Run the command 'package create -in="C:\temp\WindowsAzurePHPApp" -out="C:\temp\WindowsAzurePHPApp\build" -dev=false'

You will now have two new files inside of C:\temp\WindowsAzurePHPApp\build that will be uploaded to Windows Azure; WindowsAzurePHPApp.cspkg and ServiceConfiguration.cscfg

It is now time to upload your application to Windows Azure. Instead of repeating the deployment instructions here please see the excellent article by Jas Sandu on Deploying your PHP application to Windows Azure.

After you have uploaded your files your deployment will begin to build. This generally takes several minutes as the Windows Azure service is creating a new Windows Server 2008 instance, installing PHP, and installing your application.

When the role state changes to busy your application is ready to be viewed.

Congratulations on building a full Windows Azure PHP application from the ground up!

Additional resources

The Windows Azure SDK for PHP supports powerful configuration features and the following are links to a few MSDN articles that will help you take advantage of the capabilities offered by the Windows Azure Platform

blog comments powered by Disqus