In my previous post I mentioned I’d completed a few of the Windows Azure: Getting Started tutorials. The tutorials are ok as far as they go (displaying a single page) but when I tried launching my ZendFramework application to Azure I encountered a few issues.
1) Creating web.config
2) Getting URL Re-Writing to work
This post describes the process I went through to get my Basic application in the cloud. I am assuming some familiartiy with the tools which can be gained by completing “Deploy Your First Application With Windows Azure CLI Tools for PHP ” and “Deploying Your First PHP Application To Windows Azure“.
My application structre follows the standard structure created by Zend_Tool shown bellow.
SentimentEngine -application --models --controllers --views -modules --api ---controllers ---models ---views -library -public --img --css --js
Zend Framework requires all requests (apart from requests on files eg, img, js,css) to be routed through index.php in the public folder. The application is then bootstrapped and the response served by the aplication.
The Zend Framework library needs to be included.
Before following the steps bellow the project did not have a web.config or webrole.config, these are files used by Azure to deploy your application. The steps bellow will ensure you have the required files before deploying.
Using The Windows Azure Command Line Tool For PHP
The CLI Tools allow you to launch your project on Dev Fabric (a local staging version of App Fabric). I found the documentation of the tool to be a little light on the options and combinations of options required to launch a more complex application. So I’ll walk through the process step by step:
1) Open the SDK CLI as administrator (START > All Programms > Windows Azure SDK v1.3> Windows Azure SDK Command Prompt)
2) Navigate to C:\Program Files\WindowsAzureCmdLineTools4PHP (or wherever you installed to tool to).
3) Ensure the package.php script is working. Execute php package.php –help. If it is not go back to the tutorials above and trouble shoot.
4) I used the following command to deploy my application (lines added for clarity):
>> C:\Program Files\WindowsAzureCmdLineTools4PHP>php package.php
Project: Name of project. At first I encountered an error when using the name “TwitterSentimentEngine”. I tracked this down to be the size of the file names and paths generated by the tool where to long. I suggest using an abbrieviation like TSE to keep filenames nice and short.
Source: This should contain the entire application. “SentimentEngine” in the folder layout above.
DefaultDoc: It is important to specify this when deploying an application with a more complex structure (in this case a public directory with application and library folder above the web root). The path is relative to the source directory specified above.
PHPRuntime: This is the directory where php.exe is located on your system.
CleanRebuild: Wipes previous versions of your app off the system while building the project.
RunDevFabric: Runs the application on the dev fabric after a sucessfull build.
At this point your application’s front page should appear in the browser however you’ll notice when you try and navigate away from the front page you will get a 404. This is becuase URL Re-Writing has not been configured.
Configure URL Re-Write
The URL Re-Write module is made available by default the Azure SDK ver 1.3 and above. However in order to make it work a customised web.config is required. At this point you won’t have a web.config in your projects source code, however one was generated by the build process when you built the application.
1) Navigate to C:\Users\<USERNAME>\AppData\Local\Temp\WACmdLineTools\<PROJECT_NAME>_Build\<PROJECT_NAME>_WebRole
2) Copy web.config and web.roleconfig and paste them into the project folder (in the case the folder “SentimentEngine” above).
3) The next step is to add a Re-Write rule to the web.config file. Juozas was nice enough to provide me with the required rule. It should be inserted into the web.config like so. Do note delete any other content from this file.
Note To Self: Get a code formatting and display plugin!!
The URL attribute of the <action> tag should match the defaultDocument used in the command to build you application on the CLI.
4) Repeat the build process outlined above. The tool will now use the web.config we just created. When the Dev Fabric is launched the application should redirect to the index page correctly, you should be able to navigate through all it’s pages.
5) Finally launch the application to the Application Fabric using the Windows Azure Development Portal as described in the second tutorial above.
Evaluation Of The Platform
- The Azure CLI Tool worked well. On most occasions it outputted high quality error messages (that gave me the information I needed to solve the issues). Although there were a few exceptions for example when the xml in the web.config was malformed.
- The Devfabric is like a personal cloud. I haven’t yet taped all its potential but being able to test an entire infrastructure on a developers machine is an excellent idea.
- The documentation for the tool accurelty describes how to get a really simple cloud application up and running. I wasn’t able to find documentation covering more complex app structures.
- As someone who deploys on apache and is used to editing .htaccess files the URL Re-Write module and the web.config approach is an entirley new product to me. Including specific examples on how to get this product up and running with the PHP CLI tools would really benefit me and other users getting their framework apps on Azure.
Although it took me a while to get my simple app on to Azure I’m now convinced that I’ll be able to deploy to the platform consitently in the future. In the coming weeks as the application matures I’ll need to add support for SQL Azure and also move the Zend Framework Library over to blob storage to reduce the build time of the aplication.