Freigeben über


Using the Windows Azure Command Line Tools for PHP

Some time ago I wrote a post about how to run PHP in Windows Azure. At the heart of that post was information about using the tools that are available in the Windows Azure Software Development Kit to package a PHP application for deployment to Windows Azure. Using the command line tools in that SDK was easy enough, but you had to go through some hassle to get ready to use them (create a special directory, copy your PHP installation, create several special configuration files, etc.). The Interoperability Team at Microsoft recently released a new version of the Windows Azure Command Line Tools for PHP Developers. These tools eliminate some of the hassle I mentioned. In this post, I’ll walk you through how to use these tools.

Note: I’m assuming you have a Windows Azure Subscription. If you haven’t, steps for doing so are in this post: How to Run PHP in Windows Azure.

Note (Dec. 30, 2010) : For more up-to-date and detailed tutorials about using the Windows Azure Command Line Tools for PHP, see the following articles: Getting the Windows Azure Prerequisites via the Microsoft Web Platform Installer 2.0 and Deploying Your First PHP Application with the Windows Azure Command Line Tools for PHP.

 

The Windows Azure Command Line Tools for PHP Developers are basically a PHP wrapper for the packaging tools in the Windows Azure Software Development Kit. In fact, to use the PHP tools, you need to…

  1. Download the Windows Azure Command Line Tools for PHP Developers (and unzip the downloaded file), then…
  2. Download the Windows Azure Software Development Kit and put the downloaded zip file (PHPAzure-1.0.1.zip) in the WindowsAzureCmdLineTools4PHP\res\php directory.

Once you’ve done that, the tools are ready to use. To test an application for deployment to Windows Azure, you can run the application in the local Development Fabric with one command:

c:\WindowsAzureCmdLineTools4PHP>php package.php --project=YourProjectName --source="path_to_application_source_directory" --phpRuntime="path_to_php_installation_directory" --target="path_to_folder_for_holding_package_files" --runDevFabric

Note: When testing or deploying an application to Azure, all files paths in your php.ini file must be relative file paths. For example, when specifying your extension directory, you should do it like this: extension_dir=”.\ext”.

So, for example, to test my installation of Drupal in the local Development Fabric, I executed this command:

c:\WindowsAzureCmdLineTools4PHP>php package.php --project=DrupalInAzure --source="c:\inetpub\wwwroot\drupal" --phpRuntime="C:\Program Files (x86)\PHP" --target="c:\workspace" --runDevFabric

             Note: My instance of Drupal was configured to run against my Drupal database in SQL Azure. For instructions about running a local application against SQL Azure see Getting Started with PHP and SQL Azure.

To shutdown the Development Fabric, you have to use the Windows Azure SDK tools directly (assuming you’ve unpacked them and put them in your PATH variable):

c:\WindowsAzureCmdLineTools4PHP>csrun /devfabric:shutdown

Once you are satisfied with the application running in the local Development Fabric, you are ready to create a package for deployment to Azure. However, one step the tools don’t currently handle for you is making sure that your web.config file specifies PHP as the handler for PHP scripts. (The Interoperability Team is planning to fix this in a later release.) So, you need to add the element below to the <system.webserver> element of your application's web.config file before creating the deployment package:

<handlers>
<clear />
<add name="PHP via FastCGI"
path="*.php"
verb="*"
modules="FastCgiModule"
scriptProcessor="%RoleRoot%\approot\php\php-cgi.exe"
resourceType="Unspecified" />
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
</handlers>

Now you can run the following command to create the installation package:

c:\WindowsAzureCmdLineTools4PHP>php package.php --project=YourProjectName--source="path_to_application_source_directory" --phpRuntime="path_to_php_installation_directory" --target="path_to_folder_for_holding_package_files" --cleanRebuild

So, for example, to package Drupal for deployment, I executed the following command (after modifying the web.config file):

c:\WindowsAzureCmdLineTools4PHP>php package.php --project=Drupal --source="c:\inetpub\wwwroot\drupal" --phpRuntime="C:\Program Files (x86)\PHP" --target="c:\workspace" --cleanRebuild

Now, in my C:\workspace\Drupal_Build\Drupal directory, I find several files, but the two I need for deployment are Drupal.cspkg and ServiceConfiguration.cscfg. Once you have those, you just need to go to the Windows Azure developer portal and follow the steps for deployment at the end of this post.

That's it. I found using these tools to be very handy...definitely saved some of the work needed when using the Windows Azure SDK directly. I'd be interested in what others think of these tools.

Thanks.

-Brian

Share this on Twitter