【Azure Services Platform Step by Step-第13篇】在Windows Azure中使用PHP
,新建Web Cloud Service项目。
第五步,配置Service Definition 文件(ServiceDefinition.csdef)。
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="CloudService1" 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>
注意:需要在WebRole节点下增加enableNativeCodeExecution="true"属性
第六步:配置FastCGI和PHP
- 将刚刚下载的xcopy-deployable PHP压缩包解压缩到WebRole项目的php子目录下。
- 在WebRole项目根目录下增加Web.roleconfig文件,内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<fastCgi>
<application fullPath="%RoleRoot%\php\php-cgi.exe" />
</fastCgi>
</system.webServer>
</configuration>
这里我们使用了"%RoleRoot%"变量来获得Web Role的根目录。这也是Match 2009 CTP版本所提供的新特性之一。 - 在Web.config文件的system.webServer-handlers节下增加对PHP文件的处理:
<system.webServer>
<handlers>
<..>
<add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule"
scriptProcessor="%RoleRoot%\php\php-cgi.exe"
resourceType="Unspecified" />
</handlers>
</system.webServer>
第七步:写一些简单的代码测试一下吧!
代码:
<?php
$iipp=$_SERVER["REMOTE_ADDR"];
echo "你的IP地址是".$iipp."<br />";
echo "这是用PHP的echo命令输出的文字。<br />";
echo "<h1><font color='Red'><b>Hello PHP on Azure!</b></font></h1><br />";
echo "<a href='http://azure.cnblogs.com/'>流牛木马的Azure博客</a><br />";
echo "<font color='Blue'>以下是当前PHP环境的系统变量:</font><br />";
phpinfo();
?>
效果图:
