Click here to Skip to main content
13,297,461 members (55,127 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 21 Aug 2012

Deploying a PHP Application to Windows Azure using Command-line Tools

, 21 Aug 2012
This article will show how simple it is to run a PHP application in Windows Azure.

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.



This article will show how simple it is to run a PHP application in Windows Azure. We will utilize the Windows Azure Command-line Tools for PHP and a very simple PHP application. This article should provide enough information to get started in the Windows Azure environment.


One of the strengths and main selling points of Windows Azure as a cloud platform is that it can be utilized by developers with more than just .NET skills. One of the many alternative development platforms that can be used on Windows Azure is PHP. This article discusses how to use the Windows Azure Command-line Tools for PHP to compile a simple PHP application into a package that can be deployed on a Windows Azure Web Role. It then demonstrates that PHP was successfully installed by showing the ubiquitous PHP Info page.


There isn’t much that needs to be setup for this article. A quick stop over at to download the latest version of the Windows Azure Command-line Tools for PHP Developers is all that is needed. Download the current version which at the time of writing is dated June 2011. The download is a zip file. Save the zip file and unzip the contents. We will use this later to package our PHP application.

Note: There are a few pre-requisites before you can actually get the command line tool to work.  You will need to first install the Windows Azure SDK and PHP, if you don’t already have it.  For a quick summary on how to install these via the Web Platform Installer, check out this article

Before continuing on, a word about zip files downloaded from the web. In Windows Vista and Windows 7 the zip file is marked to tell the operating system that it may contain harmful applications. We need to remove this mark before unzipping the contents. To do this right click on the zip file and select properties from the context menu that appears. In the file properties dialog click the Unblock button at the bottom. Then continue unzipping the package.

PHP developers can utilize a large number of tools for developing their applications. These tools range from simple text editors like Notepad, vi, and Emacs to large Integrated Development Environments like Eclipse, Zend Studio, and PHPStorm. This ability to choose from multiple platforms and tools is a strength of PHP development. The developer isn’t tied into one platform or development environment. This article will not favor one development environment over another. It assumes that we already have a PHP application ready to push up to Windows Azure.

Creating the Project

For the example in this article we will create a real simple single page PHP application that will output the PHP Information table. Create a folder for the application and within this folder create a text file called index.php. Open this file and enter the following code:

<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8" />
        <title>PHP on Azure Demo</title>
        <?php phpinfo(); ?>

Save this code.

Before we begin packaging up the application to deploy on Azure, we should gather some basic information first. Make a simple table and fill in the information on the right:

Title Use Value
Azure Tools Directory We’ll need to know where the tools were downloaded to.  
Project Name The name of the project  
PHP Runtime Path The path to the local version of PHP. Do not include the trailing slash,  
Source Path The path to the source files for the application.  
Target Path The path for where the output of the package should be located.  

Once we have filled in the information in the right column we are ready to package our application. Open a command prompt. In Windows Vista and Windows 7 make sure to run the command prompt as an administrator. Navigate to the Azure Tools Directory folder and run the following command replacing the variable values with the values from the table above: php package.php --project={Project Name} --source={Source Path} --phpRuntime={PHP Runtime Path} --target={Target Path}

There are some additional, more advanced, parameters we could pass in here, but this will give us the basics that we need to package up our application.

There are a couple of errors that are commonly seen when running this script.

  1. If the following error message appears then the PHP executable isn’t in the path:

     Execute this statement then try the packager again: path = %path%;{PHP Runtime Path}

  2. If this message appears:

Then the trailing slash was added to the phpRuntime parameter.

When any error messages are cleared up we should see output similar to this:

That’s all there is to building the application into a package that we can deploy to Windows Azure. Be sure to note the location of the Deployment Package and Configuration files from this output window. We’ll need this information when we deploy the application to Windows Azure in the next section.

Deploying the Project

Deploying the application to Windows Azure is a fairly simple task. First we’ll need a Windows Azure account. A free Windows Azure trial is available through the end of September 2011 from this address:

After we have a Windows Azure account sign into the account<> using the Windows Live ID used to create the account.

Next we need to create a new hosted service. To create a new hosted service, click on “New Hosted Service” in the top ribbon of the Windows Azure Platform portal. A modal dialog that looks like this should appear:

Next we need to fill in the fields for this new hosted service. Enter the name of the service and a URL. Typically this is the same as the application name, but it doesn’t have to be. Also the URL needs to be unique across all of Windows Azure. Also enter the deployment name; again this can be the same as the application name.

Finally we need to upload the application package and the configuration file. For each of these click the “Browse Locally…” button and navigate to the package location as specified in the output from above:

Select the .cspkg file for the Package and the .cscfg file for the Configuration file. Click the OK button and Windows Azure will begin uploading the package. A warning message will probably appear alerting us to the fact that we only have one instance and two instances are recommended for high availability. Click the Yes button to override and submit the app.

Once the application has been uploaded, Windows Azure will start the deployment. After deployment has finished, we can navigate to the staging version of our application running in the Windows Azure Cloud. This staging version will have a Globally Unique Identifier (GUID) for a URL and the URL can be found in the right side of the main portal.

Clicking on this URL will open a Web Browser showing us our application:


This has been a very brief overview of how to use the Windows Azure Command-line Tools for PHP to build a package that can be uploaded to a new Windows Azure WebRole. There is a lot more that can be done with PHP within Windows Azure including utilizing Windows Azure SQL Storage. There are a lot of really good resources of information available on the Internet to learn how to do more with Windows Azure and PHP. A recommended first stop is this URL: Here links to more information from Stack Overflow, tutorials, and downloads can be found.

More information on using the Windows Azure Command-line Tools for PHP can be found on the documentation page of the CodePlex project:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Todd Spatafore
Architect Spatacoli
United States United States
Todd Spatafore is a professional web developer and software architect who enjoys living life on the bleeding edge of technology. Todd is an expert on HTML, CSS, JavaScript, ASP.NET (WebForms and MVC), C#, and Silverlight. Todd is currently a freelance software developer working on Windows 8 and Windows Phone applications.

Todd maintains his own blog at, in which he muses about current programming topics such as C#, XAML, JavaScript, HTML, CSS, and Hyper-V. Currently Todd is working on a few independent Windows Phone apps, and speaks for MSDN conferences on web application architecture, RIA development in Silverlight, Windows Azure and Windows 8.

You may also be interested in...


Comments and Discussions

QuestionPHP on Cloud Computing Pin
S.M. Zamshed Farhan15-Jan-13 4:04
memberS.M. Zamshed Farhan15-Jan-13 4:04 
Very interesting article for PHP on cloud computing. My vote is 5+. I have checked your profile as[^], but found no article count!
AnswerRe: PHP on Cloud Computing Pin
Todd Spatafore15-Jan-13 9:22
memberTodd Spatafore15-Jan-13 9:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 21 Aug 2012
Article Copyright 2012 by Todd Spatafore
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid