Colinizer: taking up residence in your tech brain

Wednesday May 5 2010

Getting Started with PHP on Windows Azure

This post will get you started with PHP development in Visual Studio for deployment to Windows Azure.

Using the FastCGI capabilities of IIS you can run PHP application on IIS and Windows Azure (in your local Development Fabric on in the Windows Azure cloud).

So, here’s how to create a simple PHP application in Visual Studio 2010 on Windows 7.

If you want to see this in video, check out my screencast interview with Dot Net Rocks TV on Azure and go to point 48:40.

  • Download the latest Windows ZIP files from http://windows.php.net/download/ (currently 5.3.2).  You should get for the VC9 x86 Non Thread Safe version.  The FastCGI system on IIS makes the use thread-safe.  Unzip the files into a folder somewhere on your system and rename the folder "PHP".
  • Ensure you have everything for IIS and CGI (i.e. FastCGI) is activated on your system for local development. 
  • Install the latest Azure SDK (checking the system requirements) – currently 1.1 (Feb 2010).
  • Start Visual Studio 2010 (which must be in run as an Administrator for the current version of the SDK) and create a new VS Cloud Project…

azphp1

  • Add the CGI Web Role…

azphp2

  • Open an Explorer window and locate your downloaded and extracted PHP folder.  Do a Copy on the PHP folder.
  • Open the folder for the web project…

azphp3

  • Paste the PHP folder (and therefore subfolders) into the web project folder and then select the Show All Files option in Solution Explorer so you can see the pasted PHP folder…

azphp4

 

  • Use the "Include in Project" option on the php folder to include it in project files, and therefore in the files deployed to Azure.

azphp5

  • Edit the Web.roleconfig file, (putting a new <application/> tag in place like this which tells IIS (locally or in the cloud) about the FastCGI interpreter for PHP…

azphp6

  • Edit Handers section of the Web.config file to include this new <add/> tag which tells IIS to use the PHP interpreter for files ending with .PHP…

 azphp7

  • Also add the new <defaultDocument/> tag above to set up "index.php" as the default document for the web application.
  • Finally add a basic index.php file using Add New Item on the web project; since there is no .PHP item – use a .TXT item (in the General category) and give the new file a .PHP extension…

azphp8

  • Enter this basic PHP code:

<? phpinfo(); ?>

  • Start up the application and you should see something like the following:

azphp9

You can now deploy this (or a real application) to Azure using the Publish function on the Cloud project as usual.

Check out this MSDN page for general help on using FastCGI interpreters with Azure.

Enjoy! :)

Microsoft and Open Source Communities are sponsoring the Make Web Not War conference on May 27th 2010, showcasing the latest cross-platform techniques and technologies, including presentations, panels, workshops, a codefest, the FTW coding competition and a party!  Open Data, HTML 5, PHP, JQuery, Mobile, SEO and the Cloud, are amongst the topics being covered.  Speakers and panelists will include myself, Microsoft Canada team members and many open source experts.

Make Web Not War

About these ads

4 Comments

  1. [...] adds to Colin's great blog post and [...]

    Pingback by Windows Azure Platform Partner Hub | Windows Azure – Getting in on the Act — Thursday May 6 2010 @ 23:05

  2. [...] Cloud. If you would like to learn more about Windows Azure, check out Colin’s Post on Deploying a PHP Application on Azure. I also have a number of posts on converting, and deploying applications on Windows [...]

    Pingback by Make Web Not War - The Aftermath — Monday May 31 2010 @ 12:17

  3. [...] CGI Web Role – a web role that runs in IIS under the Fast CGI module.  Fast CGI enables the execution of native code interpreters, like PHP, to execute within IIS.  If you’re looking for more information on this topic, check out Colinizer’s blog post. [...]

    Pingback by Azure@home Part 2: WebRole Implementation - Jim O'Neil - Developer Evangelist - Site Home - MSDN Blogs — Friday July 23 2010 @ 15:02


RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: