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

Tags:

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 " WindowsAzureCmdLineTools4PHP.zip"

clip_image001

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

clip_image002

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

clip_image003

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

clip_image004

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

clip_image005

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

clip_image006

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

clip_image007

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

clip_image008

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

clip_image009

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

clip_image010

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

clip_image011

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

clip_image013

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

clip_image014

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

clip_image015

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

clip_image016

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

clip_image017

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.

clip_image018

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.

clip_image019

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

clip_image020

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

clip_image021

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".

clip_image022

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:

<?php
echo "Hello Cloud from {$_SERVER['SERVER_NAME']} \n<br>\n<br>";
phpinfo();
?>

clip_image023

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

clip_image024

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

clip_image025

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":

clip_image026

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.

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

clip_image027

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.

clip_image028

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

clip_image029

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.

clip_image030

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".

clip_image031

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