Welcome to MSDN Blogs Sign in | Join | Help

Using 3rd Party Programming Languages via FastCGI

One of our goals for MIX was to give our developers more flexibility while ensuring they still benefit from the unique time-saving deployment, monitoring, and management features of Windows Azure.  One way in which we went about this was to enable IIS FastCGI module in the Web role.  This module enables developers to deploy and run applications written with 3rd party programming languages such as PHP.

How to Get Started

1) As with the .NET full trust example, the first step is to set the enableNativeCodeExecution attribute to true in your Service Definition file:

<?xml version="1.0" encoding="utf-8"?>

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">

  <WebRole name="WebRole" enableNativeCodeExecution="true">

    <InputEndpoints>

      <InputEndpoint name="HttpIn" protocol="http" port="80" />

    </InputEndpoints>

  </WebRole>

</ServiceDefinition>

2) Install the following required fix for FastCGI in the Windows Azure Development Fabric: http://support.microsoft.com/kb/967131.

3) To enable FastCGI, include a Web.roleconfig file in the root of your project, telling us which FastCGI application you will be using.  For example, for PHP:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.webServer>

    <fastCgi>

      <application fullPath="%RoleRoot%\php\php-cgi.exe" />

    </fastCgi>

  </system.webServer>

</configuration>

Note: The FastCGI application must be xcopy-deployable and contained in your project.  In this case, it is in the “php” subdirectory and specified via the special %RoleRoot% environment variable.  An xcopy-deployable version of PHP for Windows can be downloaded from http://php.net.

4) Finally, modify your Web.config to configure your handlers.  This tells us which paths (e.g. *.php) map to the FastCGI application:

<configuration>

  <system.webServer>

    <handlers>

      <add name="PHP via FastCGI"

           path="*.php"

           verb="*"

           modules="FastCgiModule"

           scriptProcessor="%RoleRoot%\php\php-cgi.exe"

           resourceType="Unspecified" />

    </handlers>
  </
system.webServer>

</configuration>

Putting It All Together

Now, you should be able to invoke your FastCGI application.  Here is an example of a multi-instance PHP-based application that has been one-click deployed to the Development Fabric (a simulation of the cloud environment).  It has been configured to use three Web role instances via a simple modification to the Service Configuration file:

 

As a bonus...

  1. We have also enabled the IIS URL Rewrite Module.  URL rewriting, a feature often used by FastCGI developers, enables the creation of URLs that are easier for users to remember and easier for search engines to find.
  2. The Visual Studio Tools for Windows Azure includes a FastCGI Web Role that creates a Web Application project tailored to make it easier to configure, run and package a FastCGI application.

For more detail, please refer to the documentation and FastCGI sample in the Windows Azure SDK.  Enjoy!

Published Wednesday, March 18, 2009 5:56 PM by WindowsAzure

Comments

# MIX 09... en vivo!!!

Hola que tal a todos; Como muchos de ustedes saben, en estos momentos se esta llevando a cabo en Las

Wednesday, March 18, 2009 3:05 PM by Vlad-Point Master Chief

# re: Using 3rd Party Programming Languages via FastCGI

Wow!!! Azure platform is going to rock now... adding support for PHP is really cool.. Cheers for Azure Team!!!

Wednesday, March 18, 2009 4:10 PM by adarshaj

# MIX 2009 – Nouveautes au sein de la CTP de Windows Azure : FastCGI, Full Trust et Geo-localisation

Je vous en avais parlé rapidement lors de la session plénière de ce matin, Microsoft nous a annoncé quelques

Wednesday, March 18, 2009 9:07 PM by RedoBlog - The .NET Gentleman !!!

# MIX09 での Azure アップデートについて

MIX09 Day1 キーノートでは、Silverlight の話に多くの時間を費やしたキーノートでしたので、Azure の話は目立ちませんが、いくつかアップデートを発表しております。 FastCGI,

Thursday, March 19, 2009 3:51 AM by Fumio Sekita's Blog

# Session PHP dans le monde Microsoft

Cette session du MIX09 nous présentait les différents facettes de PHP dans le monde Microsoft et principalement

Thursday, March 19, 2009 7:16 PM by David Rousset

# re: Using 3rd Party Programming Languages via FastCGI

A live Demo using PHP on Windows Azure:

http://ibm.cloudapp.net/php.php

Friday, March 20, 2009 6:48 AM by mars1021
Anonymous comments are disabled
 
Page view tracker