Deploying Your First PHP Application with the Windows Azure Command Line Tools for PHP

Author: Jas Sandhu

Date: Monday, December 27, 2010, 12:00:00 AM


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 pre-read

This walk-through assumes that you have followed the directions to install the "Windows Azure Pre-Requisites", which includes preparing the system for development with PHP and the Windows Azure SDK.

In this part 1, you will learn how to use the command line tools to package and deploy a PHP application, using the Windows Azure Compute emulator, a "local Windows Azure cloud" running on your Windows machine. In part 2, you will learn the final step, which is how to actually deploy to Windows Azure cloud platform.

1. We will be using the Windows Azure Command Line Tools for PHP available from the Codeplex project folder. ; Please visit the download page for "Windows Azure Command-line Tools for PHP Developers" and click on ""


2. Click on "I Agree", when the next screen appears.


3. Click "Open" in the "File Download" window.


4. Click on the "Allow" button in the "Internet Explorer Security" window.


5. You may see the "User Account Control" window; if so, click "Yes".


6. A Window entitled "WindowsAzureCmdLineTools4PHP" or something similar will appear. ; Click on the "Extract all files" link near the menu bar.


7. For the purposes of this demo, click on C:\Program Files and make sure the "Show extracted files when complete" checkbox is selected.


8. When the "Destination Folder Access Denied" popup appears, click on "Continue".


9. A window such as the one below may appear showing progress.


10. When it completes, you'll see a folder opened in "Program Files"


11. Navigate down to "C:\Program Files\WindowsAzureCmdLineTools4PHP"; you should see the contents of the directory including the file "package.php"


12. Next, click the "Start Button" clip_image012, then click "All Programs":


13. You should see the "Windows Azure SDK v1.3" folder. ; Navigate to it:


14. It will open a few menu items; right-click on the "Windows Azure SDK Command Prompt" selection, to "Run as administrator"


15. Click "Yes" in the "User Account Control" when it comes up;


16. You should then see the command line window below, entitled "Windows Azure SDK Environment".


17. In the command line window, change to the Windows Azure Command Line tools directory by typing the following:

cd " C:\Program Files\WindowsAzureCmdLineTools4PHP"

and type the "dir" command, to find the directory's contents.


18. Let's test and make sure that everything is installed. ; On the command line, type":

php package.php -h

You will then get the a message directing you on how to use the tool, it's parameters and advanced flags.


19. If you find that you receive an error such as the one below, please see the article, " Troubleshooting an MSVCR71.dll Error"


20. At the "Windows Azure SDK Command Prompt", type in:

mkdir %TMP%\PHPInfo

This will create a directory called PHPInfo (which will also be our project name) in the default Temporary folder for your account on this machine; typically in the form of "C:\Users\[username]\Appdata\Local\Temp\[OPTIONAL subdirectory], where your account is your username.

21. You will then be able to create some files for your application package. ; I'm going to create the default file that is launched by PHP, "index.php". ; I'll be using "Notepad" for convenience although you may pick any text editor of choice. ; From the command line, type:

notepad %TMP%\PHPInfo\index.php


22. This will launch notepad, a popup may appear and you may be asked if you would like to create a new file. Click "Yes".


23. You may then just type in your typical PHP "Hello World" application, or just package up an existing application directory. ; I'm going to type in the following application, which will just say Hello from the Cloud with the name of the server that it's called from:

echo "Hello Cloud from {$_SERVER['SERVER_NAME']} \n<br>\n<br>";


24. Click on the "File" menu item and then "Save" to save the file you just created.


25. You can test your application by typing the command below, which will test your page for errors and will output its result in text on the command line and page through it for convenience.

php %TMP%\PHPInfo\index.php | more


26. Now that we have a working and tested PHP application going, we can package it out to be used for deployment and consumption from our test cloud environment. ; Make sure you are in the directory where you unpacked the Command Line tools for Azure; in our example, "C:\Program Files\WindowsAzureCmdLineTools4PHP". ; You will find the "package.php" file in there. ; Check by typing "dir":


27. We are going to issue the command below to package up your application. In this case we have named our project "PHPInfo", given it an argument as to ; where our PHP runtime resides (typically "C:\Program Files\PHP"), as well as where we have created the directory source (in our case, the default temporary folder for this account, with the file "index.php" within.) ; I have omitted the target output directory, as I will be using the default temporary folders which our tool will output to, plus a command to run it in the development emulator. ; You may change these options at your discretion later. ; From the command line, run the command below, and you will receive output on the process and it will return the location of where the Web Role and Services packages will reside for deploying out to the Windows Azure cloud.

php package.php --project=PHPInfo --phpRuntime="C:\Program Files\PHP" --source="%TMP%\PHPInfo" --runDevFabric


Note: ; By default the package.php is looking for "index.php" as the default starting page. ; To change this you use the "--defaultDoc" parameter, for example: --defaultDoc=info.php. ; To see more advanced options you can type: "php package.php -a"

28. Once this completes, you will receive a popup such as the one below; click "Yes" to continue and it will start the local Window Azure Development Emulator for testing your cloud package.


29. A browser should run with your application on your local machine, typically (localhost) at some port number (typically higher than 80.)


30. On the taskbar on the bottom right, click the double-arrows/chevron/triangle in the area called the "notification panel", to reveal a Windows Azure Icon (a blue Windows logo). ; Right-clicking on the icon will show some menu items. ; You may also see a message popup with a balloon indicating that the "Windows Simulation Environment" has either started or shutdown the "Development Emulator" or the "Storage Emulator". ; Right-clicking the icon will also yield some useful selection items and tools that aid in understanding what is going on. ; You may want to select "Shutdown Compute Emulator" when you are done testing.


31. This verifies that our simple PHP application runs on the "Windows Azure Simulation Environment" installed on your local machine by the Windows Azure SDK in the Development Emulator. ; Basically, it's a version of the Windows Azure cloud that you have at your disposal locally and that can be used for testing without having to worry about deploying anything on the "live" Windows Azure cloud service. ; It is useful if you are just trying out different things out before you deploy to the Windows Azure environment. ; If you want to find the files necessary for deployment for Windows Azure you will find them in the folder
"C:\Users\[username]\AppData\Local\Temp\WACmdLineTools\PHPInfo_Build\PHPInfo", or type in:

cd %TMP%\WACmdLineTools\PHPInfo_Build\PHPInfo

and dir from the command line.

Replace username with your account name. ; The files you will be looking for are "PHPInfo.cspkg" and "ServiceConfiguration.cscfg".


The next step is to deploy these files to the cloud! ; For that you will want to read the article entitled "Deploying a PHP application to Windows Azure".

Happy Cloud Computing!

What's next?

blog comments powered by Disqus

Related Content

No related content was found