Visual Web Developer 2010 Expressによる開発
今回は、
ただ、
そこで、
IISでPHPを動作させる
まず、
![図1 Visual Web Developer 2010 Expressで、Windows Azure Projectを作成 図1 Visual Web Developer 2010 Expressで、Windows Azure Projectを作成](/assets/images/admin/serial/01/azure_for_lamp/0007/thumb/TH800_001.jpg)
すると、
![図2 Windows Azure Project(ASP.NET Web Role)を作成 図2 Windows Azure Project(ASP.NET Web Role)を作成](/assets/images/admin/serial/01/azure_for_lamp/0007/thumb/TH800_002.jpg)
しばらくするとVWDの画面が表示されますので、
また、
![図3 プロジェクトにphpとAdminerフォルダを追加 図3 プロジェクトにphpとAdminerフォルダを追加](/assets/images/admin/serial/01/azure_for_lamp/0007/003.jpg)
フォルダをコピーしたら、
また、
![図4 Web.config、Web.roleconfig、index.phpを追加 図4 Web.config、Web.roleconfig、index.phpを追加](/assets/images/admin/serial/01/azure_for_lamp/0007/004.jpg)
それぞれのファイルは以下のような内容です。index.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<fastCgi>
<application fullPath="%RoleRoot%\approot\php\php-cgi.exe" />
</fastCgi>
</system.webServer>
</configuration>
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener,
Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.webServer>
<!-- DO NOT REMOVE: PHP FastCGI Module Handler -->
<handlers>
<clear />
<add name="PHP via FastCGI"
path="*.php"
verb="*"
modules="FastCgiModule"
scriptProcessor="%RoleRoot%\approot\php\php-cgi.exe"
resourceType="Unspecified" />
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
</handlers>
<!-- Example WebRole IIS 7 Configation -->
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
<html>
<body>
<p>LOCAL_ADDR: <?php echo $_SERVER["LOCAL_ADDR"]; ?></p>
</body>
</html>
IISでPHPを動作させるための設定は以上です。
VHDをマウントするWebRole.csの作成
次に、
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.StorageClient;
namespace WebRole1
{
public class WebRole : RoleEntryPoint
{
private CloudDrive AzureDrive;
public override bool OnStart()
{
// 構成設定の初期値を設定
string connString = RoleEnvironment.GetConfigurationSettingValue("WindowsAzureStorageConnectionString");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connString);
// Azureドライブのマウント
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("mysql");
AzureDrive = storageAccount.CreateCloudDrive(blobContainer.GetPageBlobReference("disk.vhd").Uri.ToString());
string driveLetter = AzureDrive.Mount(0, DriveMountOptions.Force);
return base.OnStart();
}
public override void OnStop()
{
// Azureドライブのアンマウント
AzureDrive.Unmount();
base.OnStop();
}
}
}
ロールの初期化時にOnStart()、
Windows Azureドライブを利用するためには
![図5 参照設定にMicrosoft.WindowsAzure.CloudDriveを追加 図5 参照設定にMicrosoft.WindowsAzure.CloudDriveを追加](/assets/images/admin/serial/01/azure_for_lamp/0007/005.jpg)
MySQLを起動するスタートアップタスクを作成
次に、
@echo off
netsh advfirewall firewall add rule name="mysqld" dir=in action=allow program="f:\mysql\bin\mysqld.exe" enable=yes
schtasks /Create /SC MINUTE /MO 10 /TN MySQL /TR "f:\mysql\bin\mysqld.exe" /RU "NT AUTHORITY\NETWORKSERVICE" /F
ここでは、
![図6 startup.cmdをプロジェクトに追加し、Copy to Output Directoryプロパティを「Copy always」に 図6 startup.cmdをプロジェクトに追加し、Copy to Output Directoryプロパティを「Copy always」に](/assets/images/admin/serial/01/azure_for_lamp/0007/thumb/TH800_006.jpg)
Azure上でstartup.
ServiceConfiguration.cscfgとServiceDefinition.csdefの編集
まず、
前回作成したストレージアカウント
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="WindowsAzureProject1" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
<Role name="WebRole1">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
<Setting name="WindowsAzureStorageConnectionString" value="DefaultEndpointsProtocol=http;AccountName=samplestorage001;AccountKey=******" /> <!-- ←この行を追加 -->
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
ServiceDefinition.
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="WindowsAzureProject2" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole1" vmsize="ExtraSmall">
<Startup>
<Task commandLine="startup.cmd" taskType="background" executionContext="elevated"></Task> <!-- スタートアップタスクの登録 -->
</Startup>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<ConfigurationSettings>
<Setting name="WindowsAzureStorageConnectionString" /> <!-- 定義の追加 -->
</ConfigurationSettings>
</WebRole>
</ServiceDefinition>
my.iniの編集とdataのコピー
最後に、
my.
basedir="F:/mysql/"
datadir="F:/mysql/data/"
パッケージの作成とデプロイ後の確認
準備が整いましたので、
![図7 パッケージの作成 図7 パッケージの作成](/assets/images/admin/serial/01/azure_for_lamp/0007/007.jpg)
ビルドが終わると、
![図8 Adminerのログイン画面 図8 Adminerのログイン画面](/assets/images/admin/serial/01/azure_for_lamp/0007/thumb/TH800_008.jpg)
先ほどコピーしたIPアドレスと、
![図9 Adminerログイン後の画面 図9 Adminerログイン後の画面](/assets/images/admin/serial/01/azure_for_lamp/0007/thumb/TH800_009.jpg)
以上で、
なお、
次回からは、