php on windows azure training

Click here to load reader

Upload: microsoft-openness-japan

Post on 28-May-2015

2.905 views

Category:

Technology


7 download

TRANSCRIPT

  • 1. PHPonWindows Azuretrainingver.20121127-1.3.3pnop

2. Microsoft Corporation ("Microsoft")Microsoft()() Microsoft MicrosoftWindowsWindows AzureMicrosoft Corporation Copyright 2012 Microsoft Corporation. All rights reserved.2 3. About me 2011 Microsoft CorporationAll Rights Reserved. WindowsAzureDatabase Find me kuniteru.asami 4. Agenda 11. Windows Azure2. 3. 4. 5. Demo - 6. PHP7. Azure Storage8. Azure Blob9. Azure Table10. SQL Database 4 5. Agenda 211. Framework12. $_SESSION13. IIS14. 15. 16. memcached Caching17. 18. PHP on Azure 19. Appendix20. Q & A 5 6. #1Windows Azure6 7. Windows AzureFabricSQL Database Computing ControllerCloud Services CachingDatabase Load WebSitesData SyncBalancerVirtual MachineWindowsLinux BusinessAnalyticsCDN BlobDrive TableQueue Storage Networking Mobile Services Hadoop/HPC Vitrual NetworkConnectTraffic ManagerMedia Services Store 7 8. Computing1Firewall RulesVirtual Network O/S O/SVirtualization VirtualizationVirtualization Hardware HardwareHardware 9. Computing2 9 10. WebWebsites1 git pushftps GALLERYWeb DrupalJoomla!WordPress WebMatrixWeb 65Web.NET 2012/06/30 SQL DatabaseMySQL 11. Web2 OS 110 Web 3 VM 12. Virtual Machines MySQL Linux Windows Server OS PHP 13. Cloud Services 1 OS Memcached MySQL PHP 14. 2 Hosted ServiceRoleOS Web RoleWeb Worker Role VM RoleOS ExtraLarge, Large, Medium, Small, ExtraSmall Role OSIISAzure StorageSQLDatabase14 15. Azure Storage Azure Blob Azure Drive Azure Blob Azure Table Key Value Store Azure Queue 3 15 16. SQL DatabaseSQL ServerWindows Azure 2 SQL Azure16 17. Load Balancer 60 Web 17 18. CDN Azure BlobWebRoleContents Delivery Network htmlJavaScriptcss CDN 18 19. CDN24 USEMEAAsia-Pacific/Rest of World Ashburn, VA Amsterdam, NL Hong Kong, HK Bay Area, CA Doha, QT So Paulo, BR Chicago, IL Dublin, IE Seoul, KR San Antonio, TX London, GB Singapore, SG Los Angeles, CA Moscow, RU Sydney, AU Miami, FL Paris, FR Taipei, TW Newark, NJ Stockholm, SE Tokyo, JP Seattle, WA Vienna, AT Zurich, CH 19 20. #2 20 21. Windows Azure Visual Studio Visual Studio 2012, 2010 Visual Studio Express 2012 for Web Visual Web Developer 2010 Windows Azure PowerShell Windows Azure Tools for Eclipse PHPAzure WebWindows Azure Mac OS XLinuxIDEEclipse PDTNetBeansWindows AzureWeb 21 22. 1 PHP Developer CenterWindowsInstallerhttp://www.windowsazure.com/ja-jp/develop/php/ Azure SQL DatabaseMicrosoft Drivers 3.0 for PHP v5.3 for SQL Server in IIS(IIS Express) Visual StudioVisual Studio Express 2012 for Web with Windows Azure SDK 22 23. 23 24. 2 Web Platform InstallerPC Web Platform InstallerAzure PHP Non Thread Safe 24 25. Visual Studio 2012,Visual Studio 2012 Express for Web Microsoft Visual Studio 2012 Express for Web GUI SSL OnStart, OnStop, Run.NET Visual StudioVS 25 26. Windows Azure PowerShell MicrosoftPowerShell PowerShellHelpPS> help Azure HelpPS> Get-Help Publish-AzureServiceProject 26 27. PHPAzurehttp://phpazure.codeplex.com/ PHPAzureWindows Azure SDK for PHP Windows AzurePHP package PHP 1. 2. PHPPATH3. PHPAzurebinPATH27 28. Windows Azure Tools for EclipseWindowsAzure4e http://www.windowsazure4e.org/ Windows Azure SDK v1.6 Eclipse PDT + PHPIDE XdebugZend Debugger GUI SSLWindows AzurePHP php_azure.dll PHPAzure WebHWC OnStart.NET http://msdn.microsoft.com/ja-jp/windowsazure/hh240574 Windows Azure SDK v1.6 csrun.exeMicrosoft.ServiceHosting.Tools.dllSDKbinC:> mklink "%ProgramFiles%Windows Azure SDKv1.6bincsrun.exe" "%ProgramFiles%Windows Azure Emulatoremulatorcsrun.exe"C:> mklink "%ProgramFiles%Windows Azure SDKv1.6binMicrosoft.ServiceHosting.Tools.dll" "%ProgramFiles%Windows Azure EmulatoremulatorMicrosoft.ServiceHosting.Tools.dll" 28 29. #3 29 30. Role2*.cscfgServiceDefinition.csdefRoleRoleVisual Studio30 31. Role 1 *.cscfg Windows Azure Azure OS Instancecount OS ServiceConfigurationosFamily 1Windows Server 2008 + IIS 7.0 2Windows Server 2008 R2 + IIS 7.5 3Windows Server 2012 + IIS 8.0Visual Studio/Visual Web Developer 31 32. Role 2 ServiceDefinition.csdef SSL WebRoleWorkerRolevmsize ExtraSmall Small Medium Large ExtraLarge Visual Studio/Visual Web Developer 32 33. RoleRole WebRoleDOCUMENT_ROOT PHPJavaScriptcss DOCUMENT_ROOT *.cs WebRole.cs OnStartRun Web.config Apache.htaccess URL RewriteIIS diagnostics.wadcfgVisual Studio/Visual Web Developer httpd33 34. #434 35. Web1. 2. Windows AzureVSPowerShell1. Visual Studio 2012 Express for Web Windows Azure PowerShell2. WebWindows Azure 35 36. Webhttps://manage.windowsazure.com/ 36 37. #5Demo 37 38. Visual Studio 2012 Express for Web Windows Azure PowerShell Windows Azure38 39. #6 PHP 39 40. Windows AzurePHPPHP WebPi CommandPHP PHP windows.php.netWebPi CommandPHP 40 41. PHPStartup TaskOnStart.NET Startup Task OnStart .NETOnStart PHPIIS41 42. Startup Task 1 ServiceDefinition.csdef : commandLineRole executionContext elevated limitedtaskType simple background foreground 42 43. Startup Task 2 BOMUTF-8 VSBOM UTF-8 ANSIOK %ProgramFiles% %ProgramFiles(x86)% %SystemDrive% %SystemRoot% appcmd.exeIIS PowerShell @echo off43 44. OnStart 1*.csOnStart.NET namespace WebRole { public class WebRole : RoleEntryPoint { public override bool OnStart() { // // MSDN (http://go.microsoft.com/fwlink/?LinkId=166357) /**** ****/ return base.OnStart(); } } } Microsoft.Web.Administration.dllIIS 44 45. OnStart 2 IISServiceDefinition.csdefRuntime : executionContext elevated limited45 46. WebPi CommandPHP1Startup TaskWebPi CommandPHP1. %ProgramFiles%MicrosoftWeb Platform Installer4 Microsoft.Web.PlatformInstaller.dll Microsoft.Web.PlatformInstaller.UI.dll WebpiCmd.exe WebpiCmd.exe.config2. VS Azure Power ShellVS3. ServiceDefinition.csdef4. WebPiCmd setup_web.cmd 46 47. WebPi CommandPHP2 ServiceDefinition.csdef http://msdn.microsoft.com/ja-jp/library/windowsazure/hh691735(v=vs.103).aspx 47 48. WebPi CommandPHP3 setup_web.cmd@echo offECHO "Starting PHP Installation" >> log.txtmd "%~dp0appdata"cd "%~dp0appdata"cd "%~dp0"reg add "hku.defaultsoftwaremicrosoftwindowscurrentversionexploreruser shell folders"/v "Local AppData" /t REG_EXPAND_SZ /d "%~dp0appdata" /f"%~dp0AssetsWebPICmd.exe" /Install /Products:PHP53,SQLDriverPHP53IIS /AcceptEula >>log.txt 2>>err.txtreg add "hku.defaultsoftwaremicrosoftwindowscurrentversionexploreruser shell folders"/v "Local AppData" /t REG_EXPAND_SZ /d %%USERPROFILE%%AppDataLocal /fECHO "Completed PHP Installation" >> log.txt 48 49. WebPi CommandPHP4 Windows Azure PowerShellAdd-AzurePHPWebRole PHP PS> Import-Module "C:Program FilesMicrosoft SDKsWindows AzurePowerShellAzureAzure.psd1" PS> New-AzureServiceProject ServiceName: phppj PS> cd phppj ServiceName PS> Add-AzurePHPWebRole PS> cd WebRole1bin PS> dir Directory: C:tempphppjphptestWebRole1bin ModeLastWriteTime Length Name ----------------- ------ ---- -a---10/25/2012 12:49 PM2101 download.ps1 -a--- 9/13/2012 11:41 AM1446 setup.cmd -a--- 9/13/2012 11:41 AM1268 setup.ps1 -a---10/31/2012 8:08 AM 1497 setup_web.cmd 2012/11/28WebPI 49 50. Windows Azure PowerShellPHP11. Azure PS> Import-Module "C:Program FilesMicrosoft SDKsWindows AzurePowerShellAzureAzure.psd1" PS> Get-AzurePublishSettingsFile Web PS> Import-AzurePublishSettingsFile {} PS> mkdir ~phppj PS> cd ~phppj PS> New-AzureServiceProject ServiceName: phppj PS> cd phppj ServiceName PS> Add-AzurePHPWebRole2. 2012/11/28WebPIWebRole1setup.cmdWebPI .webpicmdline /Products:PHP53,SQLDriverPHP53IIS,PHPManager /AcceptEula>> ..startup-tasks-log.txt 2>>..startup-tasks-error-log.txt .webpicmd /Install /Products:PHP53,SQLDriverPHP53IIS,PHPManager /AcceptEula>> ..startup-tasks-log.txt 2>>..startup-tasks-error-log.txt 50 51. Windows Azure PowerShellPHP23. %ProgramFiles%MicrosoftWeb Platform Installer 4 Microsoft.Web.PlatformInstaller.dll Microsoft.Web.PlatformInstaller.UI.dll WebpiCmd.exe WebpiCmd.exe.config4. PS> Publish-AzureServiceProject Location East Asia -PackageOnly 51 52. #7 52 53. Azure Blob OS 1. 2. Azure Storage 3. 4. 53 54. #8Azure Storage54 55. Windows Azure 55 56. Windows Azure SDK for PHPPHPAzure StorageWindows Azure SDKfor PHPWindows Azure SDK for PHP2 Microsoftgithubhttps://github.com/WindowsAzure/azure-sdk-for-php PHPAzure - Windows Azure SDK for PHPhttp://phpazure.codeplex.com/githubPHPAzuregithub2012/11/29PHPAzuregithubgithubSDK56 57. #9Azure Blob 57 58. Azure BlobAzure Blob1/Azure Blob/PublicPrivatePublichttp/httpsAzurehttps://.blob.core.windows.net//58 59. Azure Blob Neudesic Azure Storage Explorer CloudBerry Explorer Gladinet ClumsyLeaf CloudXplorer Cyberduck myAzureStorage etc...CloudBerry Explorer59 60. PHPAzure Blob1Azure BlobWindows Azure SDK for PHP ServiceBuildercreateBlobService// Windows Azure SDK for PHP require_once vendorautoload.php;use WindowsAzureCommonServicesBuilder;use WindowsAzureCommonServiceException;use WindowsAzureBlobModelsCreateBlobOptions;$protocol = https; // Storage http or https$accountName = YOUR STORAGE ACCOUNT; // $accountKey = YOUR STORAGE ACCOUNT KEY; // $connectionString = DefaultEndpointsProtocol= . $protocol . ;. AccountName= . $accountName . ;. AccountKey= . $accountKey;// Windows Azure Storage$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); 60 61. PHPAzure Blob2 createBlockBlobcreateBlockBlobBlock Blob // $content = fopen(C:sample.png, r); $blob_name = sample.png; //Content-Type $blobOptions = new CreateBlobOptions(); $blobOptions->setContentType(image/png); // $blobRestProxy->createBlockBlob(public, $blob_name, $content, $blobOptions);Content-Typeimage/png How to use the Blob service from PHPhttps://www.windowsazure.com/ja-jp/develop/php/how-to-guides/blob-service/ Windows Azure SDK for PHP API Documentationhttp://dl.windowsazure.com/phpdocs/namespaces/WindowsAzure.Blob.html61 62. #10Azure Table62 63. Azure Table 1Azure Table KVS (Key value Store) RDBMS 63 64. Azure Table 2Partitionkey Rowkey Timestamp first lastusers12012/01/08 users22012/01/21 users32012/01/30users42012/02/13users52012/02/28 255 64 65. Azure Table 3 255 Partitionkey/Rowkey/Timestamp RDBMS Partitionkey 65 66. Azure Table Neudesic Azure Storage Explorer ClumsyLeaf TableXplorer myAzureStorageAzure Storage Explorer 66 67. PHPAzure Table 1Azure TableWindows Azure SDK for PHP ServiceBuildercreateBlobService// Windows Azure SDK for PHP require_once vendorautoload.php;use WindowsAzureCommonServicesBuilder;use WindowsAzureCommonServiceException;use WindowsAzureTableModelsEntity;use WindowsAzureTableModelsEdmType;$protocol = https; // Storage http or https$accountName = YOUR STORAGE ACCOUNT; // $accountKey = YOUR STORAGE ACCOUNT KEY; // $connectionString = DefaultEndpointsProtocol= . $protocol . ;. AccountName= . $accountName . ;. AccountKey= . $accountKey;// Windows Azure Storage$blobRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);67 68. PHPAzure Table 2 insertEntity // $tableRestProxy->createTable("mytable"); // () $entity = new Entity(); $entity->setPartitionKey("tasksSeattle"); $entity->setRowKey("1"); $entity->addProperty("Description", null, "Take out the trash."); $entity->addProperty("DueDate",EdmType::DATETIME,new DateTime("2012-11-05T08:15:00-08:00")); $entity->addProperty("Location", EdmType::STRING, "Home"); // $tableRestProxy->insertEntity("mytable", $entity); How to use the Table service from PHPhttps://www.windowsazure.com/ja-jp/develop/php/how-to-guides/table-service/ Windows Azure SDK for PHP API Documentationhttp://dl.windowsazure.com/phpdocs/namespaces/WindowsAzure.Table.html Windows Azure Table http://msdn.microsoft.com/ja-jp/windowsazure/hh39842868 69. #11SQL Database 69 70. SQL DatabaseSQL DatabaseMicrosoft SQL Server RDBMSSQL Server Transact-SQL T-SQL Windows Azure RDBMS SQL Database23 70 71. SQL Database SQL Database Microsoft SQL Server Management Studio 2008 R2 SP1Microsoft SQL Server Management Studio 2008 R2 SP1 71 72. Windows Azure[+] - SQL - 72 73. 1SQL Database2 ID Windows Azure1T-SQL Windows Azure + ".database.windows.net"ex. abcd1234.database.windows.net + "@" + Windows Azure +ex. yourename@abcd1234 73 74. 2 IP Windows Azure Windows AzureIP Windows AzureWINDOWS AZURE 5 74 75. PHPSQL Database 1PHPSQL DatabaseMicrosoft Drivers forPHP for SQL Serverhttp://www.microsoft.com/downloads/en/details.aspx?FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05Microsoft Drivers for PHP for SQL ServerPHPPCWeb Platform InstallerWindows AzureWebPi CommandWebPi Command PHP /ProductsSQLDriverPHP53IISphpinfo()sqlsrvPDOpdo_sqlsrvPHPURL 75 76. PHPSQL Database 2 sqlsrvWeb.config93 94. #15 94 95. OS VIP Swap In-Place Upgrade Windows Azure Web Hosting Suite95 96. VIP SwapVIP VIP Swap 96 97. In-Place Upgrade5 Role 2 97 98. Windows AzureWeb Hosting SuiteFTPFTPWebhttp://azurehosting.codeplex.com/ FTP FTP FTPWebWeb98 99. gitSubversion Azure Blob 99 100. #16100 101. Azure StorageSQL Database Azure Storage6SQL Database3 Azure StorageAzure Storage SQL Database BCP DACSQL Database SQL Database Data Sync SQL Database Data Copy 101 102. #17memcached Caching 102 103. Windows Azure CachingmemcachdCaching WebWebWorker CachingCachingMemcache Memcacheshim 103 104. =memcache_default / =Internal / =tcp / =11211 104 105. NuGetWindows Azure Caching Memcache Shim web.configWebapp.configWorker autoDiscovery default config which is used for all Named Caches localhostmemcached 105 106. PHPmemcached php_memcache.dll PHPextphp_memcache.dll php.iniextension=php_memcache.dll http://downloads.php.net/pierre/php_memcache-2.2.6-5.3-nts-vc9-x86.zip106 107. #18107 108. 1 Windows Azure Platform WebSQL Database(PHP) DB HTTPWorkerRole() Azure Storage BlobCDN Web108 109. 2 Windows Azure PlatformL x 20, M1 MySQLL x 5, M5 HTTPWebHTTP (PHP) GREE L x 20 User DB(My SQL) L x 5 M MASTER DB M3 (phpMyAdmin) TEMP DB MM2 PHP,M2 Azure StorageAzure Storage My SQL109 110. 2 Windows Azure PlatformL x 20, M1 SQL Database 70GBHTTPWebHTTP (PHP) GREE L x 20 User DB50GB M MASTER DB 10GB TEMP DB M 10GB PHP,M2 Azure Storage 110 111. 3 Windows Azure Platform() SQL Database Web(PHP)4 S6 DB HTTP() Web(PHP) DB S6 DB() Web(PHP) XS2DB()Web(PHP) PHP,FTPXS2XS1Azure Storage Blob CDN/ 111 112. 2 mixiXmas Windows Azure PlatformHTTPWeb Role memcachedHTTP (.NET) mixi Worker Role Table QueueCDN BlobAzure Storage112 113. #19PHP on Azure 113 114. SQL Database N SQL Database UTC PHPAzure Web Azure 114 115. 1 Azure Azure BlobSQL Database Framework OSIISStartup TaskOnStart 115 116. 2 Windows Azure Tools for Eclipsephp_azure.dll Eclipse PDT Full IISWeb 2 Azure OS121 Startup TaskANSI UTF-8 BOM VSUTF-8 BOMAzure116 117. Blob 117 118. #20Appendix 118 119. PHP APC Windows Cache Extension for PHPhttp://www.iis.net/download/wincacheforphphttp://www.php.net/manual/ja/book.wincache.php WebPiCmd webpicmd.exe /Install /Products:PHP53,wincache53 /AcceptEula119 120. iOSAndroidWindows Azure StorageiOSAndroidWindows Azure StorageToolkit Windows Azure Toolkit for iOShttps://github.com/WindowsAzure-Toolkits/wa-toolkit-ios Windows Azure Toolkit for Androidhttps://github.com/WindowsAzure-Toolkits/wa-toolkit-android120 121. Windows AzureSMTPWindows AzureSMTP IPOffice 365SendGridSMTP How to Send Email Using SendGrid https://www.windowsazure.com/en-us/develop/net/how-to- guides/sendgrid-email-service/121 122. Windows Azure Toolkitfor Social Gameshttps://github.com/WindowsAzure-Toolkits/wa-toolkit-gamesWindows Azure Toolkit for Social GamesWindowsAzure122 123. cronLinuxcronWindowsWindows AzureschtasksStartup TaskOnStart schtasksC:> schtasks /Create /? schtasksschtasks /create /sc daily /MO 1 /tn SampleTask /ru "NT AUTHORITYLOCALSERVICE"/tr "%%ProgramFiles(x86)%%phpphp.exe %~dp0batchtest.php" /st 00:00Azure123 124. Azure OSAzure OSAzureOSAzure OS ServiceConfig.cscfgServiceConfigurationosVersionAzure OS xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*">osFamily PHP on IIShttp://technet.microsoft.com/ja-jp/iis/ee794964.aspx Windows Azure - http://msdn.microsoft.com/ja-jp/windowsazure/cc974147126 127. & Cloud Developers Fieldhttp://www.microsoft.com/japan/windowsazure/events/hol/127 128. Windows Azure - http://social.msdn.microsoft.com/Forums/ja-JP/windowsazureja/threads SQL Azure http://social.msdn.microsoft.com/Forums/ja-JP/sqlazureja/threads Internet Information Services http://social.technet.microsoft.com/Forums/ja-jp/iis7ja/threads PHP on Windowshttp://social.technet.microsoft.com/Forums/ja-jp/phpwinja/threads128 129. Japan Windows Azure User Grouphttp://r.jazug.jp/ 129 130. Q&A130