Demystifying The Code

Hosting a PHP Application in Windows Azure


At MIX ‘09 we (Microsoft) announced support for FastCGI in Windows Azure.  FastCGI allows us to host applications like PHP both safely and performantly (warning – performantly is not a real word).  In this post, I will begin with a very brief overview of what Windows Azure is and why you might consider hosting your PHP apps on Windows Azure.  I will then provide you with a couple of resources that you can use to easily publish your PHP application to Windows Azure, including a link to a screencast I created that illustrates just how to publish a PHP application to Windows Azure.


PHP Interop Series

This is part of a small series of blog posts and screencasts that I am doing on interoperability between PHP and the Microsoft stack.  My goal is to illustrate some features of the MS stack that PHP developers can take advantage of, as well as to illustrate how it is done.


What is Windows Azure (from 30,000 feet)

Simply put, Windows Azure is a cloud platform.  The platform provides the ability to host applications (Web Applications, Web Services and Services that don’t accept HTTP Requests) and to store and retrieve data in the cloud.  The important part of the last sentence is “in the cloud”.  Clearly, Windows Server 2008 (along with a multitude of other operating systems) provides the services to host applications and store and retrieve data.  The “in the cloud” part is the clear differentiator for Windows Azure.

You might then think that the cloud to Microsoft would simply be one or several datacenters filled with servers running Windows Server 2008 either virtually or on physical servers.  However, it is much more than that.  What differentiates Windows Azure from that environment is something known as the Windows Azure fabric.  This fabric ties all of the Azure nodes together into a cohesive whole.  This fabric provides several benefits to the applications running in Windows Azure, including manageability and health monitoring.

Windows Azure provides a portal where the application owner can simply configure how many instances of an application are running in the cloud.  In the case of web applications running on multiple instances, you need not worry about configuring the load balancer.  The Windows Azure fabric handles that for you.  For example, if you decide that you want your application running on 5 instances instead of 2, you simply change a single setting in a configuration file.  Windows Azure does the rest.  You application is deployed on 3 additional instances that are wired appropriately to the load balancer.

What happens when one of these instances is no longer healthy?  Another of the functions of the fabric is to monitor the health of the applications and servers.  Windows Azure will simply bring up another instance of your application and re-route traffic to that new, healthy instance.  Think of the complexity of building this kind of tolerance yourself.


Why Host my PHP Application in Azure?

Some of the benefits of hosting your application in Azure should be apparent from the preceding discussion.  They include scalability, availability and manageability.  Other benefits that may not be so apparent are the fact that you only pay for what you use and there is no lead-time required to bring up instances of your applications.

Pay for what you use / Lead time required

A key differentiator between all cloud platforms (not just ours) and hosted environments is that with cloud platforms you only pay for what you use and do not have to commit to future use.  In a typical hosted environment, you will likely have to commit to a defined term of use.  Further, in hosted environments, there is often a lead time required to get up and running.  There are obviously exceptions to this, notably in shared hosting scenarios.  However, if you are looking for dedicated hosting on a number of nodes, you will probably find that a significant lead time is required, along with a long-term contract. 

With Windows Azure, you simply pay for what you use and the only lead-time that is required is the amount of time required to spin up the new node.  This provides you with the flexibility to spin up new instances when demand requires and scaling back when that action is warranted. 

Scalability and Availability

This pay for what you use model allows you to scale up when demand requires and scale back when demand is down.  This can be great for startups that are intellectual property rich and cash poor.  They do not want to invest heavily in the infrastructure required to meet their forecasted demand.  However, they do want to be able to meet demand if their product or service takes off.  Further, because the Windows Azure fabric is monitoring the health of your application instances, re-routing requests to new instances where required, you can be self-assured that your application will be available to your customers.


The goal of any abstraction layer is to hide the complexity of a given task from the end user, allowing them to focus on business-specific problems.  By hosting your PHP application in Windows Azure, you need not worry about provisioning servers, configuring the operating systems, administering patches, deploying instances of web applications and wiring them to load balancers.  All of this is neatly handled for you.  All you have to do is simply deploy your application to the Azure portal and change some simple configuration settings.


Resources for Publishing your PHP Application to Azure

The following are some resources that you can take advantage of.  They make it easy to publish your PHP application to Windows Azure.  They include a screencast I put together that details every step, a comprehensive blog post by Wade Wegner that lists the steps for publishing (this is what I used when I first did it), along with a link to a blog post I put together that illustrates how to get started with Azure.  The last post shows you all of the steps required to sign up for Windows Azure.

Comments Please

Please leave me a comment, letting me know whether this post / series is helpful to you or not.  I would really appreciate it!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Demystifying The Code