I recently returned from MIX09 – what a fantastic event! So many great things were announced; so many that there’s no way I can list them all here. Please visit http://live.visitmix.com/ for access to the keynote videos and all the breakout sessions. I would also recommend reading the day one recap and the day two recap.
One of the major announcements was new capabilities for the Windows Azure CTP. This includes the support for FastCGI, Full Trust, and Geo-location. Please take a look at the Windows Azure team’s blog for all the announcements.
In this post, I want to walk you through the step you need to take to run a PHP application on Windows Azure. As you’ll see, it’s quite simple and straightforward – after a few configuration updates and additional steps, you can run nearly any PHP application. This walkthrough assumes that you have installed the latest bits for Windows Azure. If you are just getting started with Azure, please visit http://www.azure.com/ – this is the primary landing page for the Azure Services Platform. If you want to get the updated bits that allows for Full Trust and FastCGI, you can grab the bits at the Windows Azure Tools for Microsoft Visual Studio March 2009 CTP page.
Create a new project. Select File –> New –> Project.
Select Cloud Service project type and select the Blank Cloud Service template. Specify the name/location, and click OK.
Now we need to actually grab the PHP executable that will bet invoked. Browse to http://www.php.net/downloads.php and grab the non-thread-safe Windows binary (at the time of writing, it is “PHP 5.2.9-1 Non-thread-safe zip package”).
You might as well configure PHP to run on your Windows environment. Rather than specifying all these steps, please see Simon Guest’s post on hosting PHP applications in 5 easy steps. Follow the steps in his post, and at the end you should be able to confirm that PHP works in IIS 7.
Copy all the files in the PHP folder you downloaded into your Cgi Web Role project. XCopy works really well. For example, open a command prompt in the root of your Cgi Web Role project and type: xcopy /s php php When asked, specify “D for directory”. This will copy everything from c:php into a folder called php in your Cgi Web Role project. Note that this is where we pointed Windows Azure to in step 5.
Select your Cgi Web Role project, show all files, and add the new php folder into your project. This way it will get packaged up with the rest of your application and deployed to Windows Azure.
Open up the Web.config file and specify a new default document. This will tell Windows Azure to open up our PHP page by default. Under the <system.webServer> element, add a
And that’s all it takes!
While this is a simple demonstration, I hope it impresses upon you the impact that allowing native code execution has in Windows Azure. With native code execution, and fast CGI support, you can now leverage all the rich content created in the PHP community on Windows Azure. The story even gets better with the new relational capabilities of SQL Data Services, but I’ll save that for another post.
I hope this helps!