【第13篇】在Windows Azure中使用PHP

在微软MIX09大会上,Windows Azure发布了它的第3个版本——Match 2009 CTP。从这个版本开始,Windows Azure开始支持FastCGI。(详见MIX09-Windows Azure (March 2009 CTP)里振奋人心的新特性一览,by 流牛木马) 支持FastCGI,也就是意味着支持PHP、Ruby、Python等当前流行的"非微软"web应用程序。我们很欣喜地看到Azure Services Platform迈出了“开放平台”的第一步。

PHP也许是当前web开发界最最流行的语言,所以“在Azure中使用PHP”这个问题引起了很多人的关注,流牛木马本人在最近两天也收到了好几个朋友的焦急求助。

也许是微软的那些牛人们最近在忙MIX09的缘故,提及Azure支持"FastCGI”的新闻报道很多,而却几乎没有提及具体怎样在Azure里配置使用PHP。就连在新版的Azure SDK里面,关于FastCGI的sample也不是使用php的。

不用着急,在本篇中,流牛木马将会演示在Azure中使用PHP的最详细流程。

(已部署到云端的Demo: http://ibm.cloudapp.net/php.php

第一步,你必须知道的一些有关PHP&FastCGI的基本知识。

          FastCGI的官方网站:http://www.fastcgi.com/

          PHP的FastCGI模式:http://www.blogme.cn/node/6529

第二步,启用你IIS7中的FastCGI模块。
【注:本地调试环境需要。如果你打算直接部署到Cloud上,则不需要这一步。】
   (下面以Vista Ultimate中文版为例:)

  1. 打开控制面板,进入”打开或关闭Windows 功能”
    【第13篇】在Windows Azure中使用PHP
  2. 启用以下模块(图中红框的部分)
    【第13篇】在Windows Azure中使用PHP
  3. 下载安装最新的FastCGI模块:http://support.microsoft.com/kb/967131

第三步,下载一个"xcopy-deployable”版本的PHP。

    "xcopy-deployable”这个词来自微软的官方文档,但是很遗憾,在php的官方网站http://php.net/中,我们却没有找到这个词. - -P

    根据词义理解一下:可以直接拷贝部署的PHP版本。通俗地说就是不需要安装的。

    来到PHP官方网站的下载中心:http://www.php.net/downloads.php,在Windows Binaries部分找到最新版本号的"zip package“就可以了。比如现在php版本的最新版本是2009年3月10日的5.2.9-1,下载地址: http://cn2.php.net/get/php-5.2.9-1-Win32.zip/from/a/mirror

第四步,新建Web Cloud Service项目。

    【第13篇】在Windows Azure中使用PHP

第五步,配置Service Definition 文件(ServiceDefinition.csdef)。

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt【第13篇】在Windows Azure中使用PHPxml version="1.0" encoding="utf-8"?>
【第13篇】在Windows Azure中使用PHP
<ServiceDefinition name="CloudService1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
【第13篇】在Windows Azure中使用PHP 
<WebRole name="WebRole" enableNativeCodeExecution="true">
【第13篇】在Windows Azure中使用PHP   
<InputEndpoints>
【第13篇】在Windows Azure中使用PHP     
<InputEndpoint name="HttpIn" protocol="http" port="80" />
【第13篇】在Windows Azure中使用PHP   
InputEndpoints>
【第13篇】在Windows Azure中使用PHP 
WebRole>
【第13篇】在Windows Azure中使用PHP
ServiceDefinition>
【第13篇】在Windows Azure中使用PHP

      注意:需要在WebRole节点下增加enableNativeCodeExecution="true"属性

 

第六步:配置FastCGI和PHP

  1. 将刚刚下载的xcopy-deployable PHP压缩包解压缩到WebRole项目的php子目录下。
    【第13篇】在Windows Azure中使用PHP
  2. 在WebRole项目根目录下增加Web.roleconfig文件,内容如下:
    <!--

    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/

    --&gt【第13篇】在Windows Azure中使用PHPxml version="1.0" encoding="utf-8" ?>
    【第13篇】在Windows Azure中使用PHP
    <configuration>
    【第13篇】在Windows Azure中使用PHP 
    <system.webServer>
    【第13篇】在Windows Azure中使用PHP   
    <fastCgi>
    【第13篇】在Windows Azure中使用PHP     
    <application fullPath="%RoleRoot%\php\php-cgi.exe" />
    【第13篇】在Windows Azure中使用PHP   
    fastCgi>
    【第13篇】在Windows Azure中使用PHP 
    system.webServer>
    【第13篇】在Windows Azure中使用PHP
    configuration>

    这里我们使用了"%RoleRoot%"变量来获得Web Role的根目录。这也是Match 2009 CTP版本所提供的新特性之一。
  3. 在Web.config文件的system.webServer-handlers节下增加对PHP文件的处理:
    <!--

    Code highlighting produced by Actipro CodeHighlighter (freeware)
    http://www.CodeHighlighter.com/

    --&gt【第13篇】在Windows Azure中使用PHP  <system.webServer>
    【第13篇】在Windows Azure中使用PHP         
    <handlers>
    【第13篇】在Windows Azure中使用PHP       
    <..>
    【第13篇】在Windows Azure中使用PHP   
    <add name="PHP via FastCGI"  path="*.php"  verb="*"  modules="FastCgiModule"
    【第13篇】在Windows Azure中使用PHP             scriptProcessor
    ="%RoleRoot%\php\php-cgi.exe"
    【第13篇】在Windows Azure中使用PHP             resourceType
    ="Unspecified" />
    【第13篇】在Windows Azure中使用PHP     
    handlers>
    【第13篇】在Windows Azure中使用PHP    
    【第13篇】在Windows Azure中使用PHP   
    system.webServer>

第七步:写一些简单的代码测试一下吧!
     代码:

<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt【第13篇】在Windows Azure中使用PHPphp
【第13篇】在Windows Azure中使用PHP
【第13篇】在Windows Azure中使用PHP
$iipp=$_SERVER["REMOTE_ADDR"];
【第13篇】在Windows Azure中使用PHP
echo "你的IP地址是".$iipp."
";
【第13篇】在Windows Azure中使用PHP
【第13篇】在Windows Azure中使用PHP
echo "这是用PHP的echo命令输出的文字。
";
【第13篇】在Windows Azure中使用PHP
【第13篇】在Windows Azure中使用PHP
echo "

Hello PHP on Azure!


";
【第13篇】在Windows Azure中使用PHP
【第13篇】在Windows Azure中使用PHP
echo "流牛木马的Azure博客
";
【第13篇】在Windows Azure中使用PHP
【第13篇】在Windows Azure中使用PHP
echo "以下是当前PHP环境的系统变量:
";
【第13篇】在Windows Azure中使用PHP
phpinfo();
【第13篇】在Windows Azure中使用PHP
?>
【第13篇】在Windows Azure中使用PHP


     效果图:
     【第13篇】在Windows Azure中使用PHP

原文:http://www.cnblogs.com/azure/archive/2009/03/20/1417885.html

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21507842/viewspace-592065/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/21507842/viewspace-592065/