Build new applications in the cloud - or use interoperable services that run on Microsoft infrastructure to extend and enhance your existing applications. You choose what's right for you.

Table of Contents

 

Lab 1.1 — Windows Azure Web Application

Getting Started with Hello World

 

In this lab, use Windows Azure Toolkit for Eclipse to build, package and execute a simple PHP application as a Windows Azure Service running on the local development fabric. You will also learn about deploying simple PHP Windows Azure project as a packaged application to the Windows Azure cloud.

 

This lab will not address any of the Windows Azure Storage functionalities.

 


 

Task 0 — Prerequisites

 

Before doing this lab, if you not done so:

 

  1. Complete install of Windows Azure for Eclipse

 


 

Task 1 — Create a PHP Windows Azure Web Project

 

In this task, you will create a basic PHP Web project that will be used within a Windows Azure Web Site.

 

  1. Start Eclipse with Windows Azure PHP Projects plug-in installed.
  2. Assign or Create workspace folder as Eclipse starts.
  3. Initially, starting Eclipse typically defaults to be in PHP perspective. To be sure for this lab, open PHP perspective in Eclipse.
    1. In Eclipse menu-bar, select Window menu
    2. In Window menu, select Open Perspective menu-item
    3. In Open Perspective menu-item, select PHP cascading menu-item
  4. In the PHP perspective, consider creating a PHP project.
    1. In Eclipse menu-bar, select File menu.
    2. In File menu, select New menu-item.
    3. For New menu-item, note that the initial cascading menu-items are:
      • PHP Project
      • Project...
    4. Note that initial cascading menu-items for New menu-item in will change within PHP Windows Azure perspective.
  5. Change Eclipse perspective from PHP to PHP Windows Azure.
    1. In Eclipse menu-bar, select Window menu.
    2. In Window menu, select Open Perspective menu-item.
    3. In Open Perspective menu-item, select Other... cascading menu-item.
    4. In Open Perspective panel, select PHP Windows Azure
  6. In the PHP Windows Azure perspective, Create a new PHP Windows Azure Project.
    1. In Eclipse menu-bar, select File menu.
    2. In File menu, select New menu-item.
    3. For New menu-item, note that the initial cascading menu-items has changed in PHP Windows Azure perspective:
      • Windows Azure Web Project
      • PHP Project
      • Project...
    4. In New menu-item, select Windows Azure Web Project cascading menu-item.
    5. In new PHP Azure Project panel:
      1. Provide project name HelloAzure
      2. In Data Storage Options, select None.

        This selection means that no Windows Azure Storage functionality will be configured into this new project.

      3. Select Finish button
  7. Note that in the PHP Explorer, examine the structure of the created solution.

    Two PHP projects have been created:

    • Service project: HelloAzure
    • Web Role project: HelloAzure_WebRole

 


 

Task 2 — Default Contents of a PHP Windows Azure Web Project

 

When creating a PHP Windows Azure Web project without Windows Azure Storage functionality configured, Windows Azure Toolkit for Eclipse provides a solution that ready to run in both the Development Fabric and within the Windows Azure Cloud.

 

In this task, you are going to understand what are the contents a default PHP Windows Azure Web project.

Toolkit's basic Web Role Project

The toolkit's default basic Web Role project is a standard PHP Web application project template that has been modified to work with Windows Azure.

 

The Web Role project for this lab is HelloAzure_WebRole

 

The toolkit's default contents of a basic Web Role project are:

Toolkit's basic Service Project

The toolkit's default basic Service project contains definition and configuration to run the Web Role in the Development Fabric and the Windows Azure Cloud.

 

The Service project for this lab is HelloAzure.

FILE ServiceDefinition.csdef

ServiceDefinition.csdef contains the metadata needed by the Windows Azure fabric to understand the requirements of your application, such as which roles are used. It will also contain configuration settings that apply to all instances. These configuration settings can be read using the Windows Azure API as you will see in a later exercise.

 

The Web Role element describes a role that accepts external requests via HTTP and/or HTTPS endpoints.

XML — ServiceDefinition.csdef
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition 
    name="HelloAzure" 
    xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebRole" enableNativeCodeExecution="true">
    <ConfigurationSettings>      
    </ConfigurationSettings>
    <InputEndpoints>
      <!-- Must use 
           port 80 for http 
           and port 443 for https 
           when running in the cloud -->
      <InputEndpoint name="HttpIn" protocol="http" port="80" />
    </InputEndpoints>
  </WebRole>
</ServiceDefinition>

FILE ServiceConfiguration.cscfg

ServiceConfiguration.cscfg contains values for configuration settings as defined by ServiceDefinition.csdef, and the number of instances to run for each role.

XML — ServiceConfiguration.cscfg
<?xml version="1.0" encoding="UTF-8"?>
<ServiceConfiguration 
	xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" 
	serviceName="HelloAzure">
  <Role name="WebRole">
    <ConfigurationSettings/>
    <Instances count="1"/>
  </Role>
</ServiceConfiguration>

 


 

Task 3 — Run in local Development Fabric

 

In this task, you will run your service locally in the Development Fabric.

 

You will modify the index.php page, then build and execute the Web Role in the Development Fabric.

 

Modify Web Page "index.php"

  1. Open the index.php page.
  2. Change the contents of the <title> tag to Hello Windows Azure.
  3. Change the contents of the <h1> tag Welcome to the world of Cloud Computing.
PHP — index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
  <title>Windows Azure PHP Info</title> 
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> 
</head> 
 
<body> 
 
<h1>Windows Azure PHP Info</h1> 
   
<h2>PHP Information</h2> 
<p> 
<?php phpinfo(); ?> 
</p> 
 
</body> 
</html>

 

Set Web Page "index.php" as Web Role's Default Document

Note that a Web Role's default document index.php can be set in two locations.

  1. Edit file web.config so that the defaultDocument is index.php:
    XML — web.config
    <?xml version="1.0"?>
    <configuration>
      <system.webServer>
      
      <!-- ... -->
        
        <!-- Example WebRole IIS 7 Configation -->
        <defaultDocument>
          <files>
            <clear />
            <add value="index.php" />
          </files>
        </defaultDocument>
        
      </system.webServer>
    </configuration>
    
  2.  

  3. or, Modify HelloAzure service project through Properties panel:
    1. Open PHP Explorer view.
    2. Right-click HelloAzure_WebRole project.
    3. In project menu, select bottom menu-item Properties.
    4. In left-panel, expand Windows Azure tree and select Web Configuration.
    5. In right-panel Web Configuration, select Add button.
    6. This will open HelloAzure_WebRole directory.
    7. In HelloAzure_WebRole directory, select file index.php, then Open button.
    8. The default document for HelloAzure_WebRole project is now index.php.

 

Web Role Deployments

To set the number of Web Role deployments to 2 when Windows Azure service starts:

 

Development Fabric

  1. To start Development Fabric:
    1. Right-click its icon in the system tray and select Start Development Fabric Service
  2. To view Development Fabric UI:
    1. Right-click its icon in the system tray and select Show Development Fabric UI
    2. Note that there are no WebRole(s) deployed within Development Fabric
  3. To start deployment of Web Role in local Development Fabric, perform either of the following:
    1. From Eclipse menu-bar...
      1. Open PHP Explorer view
      2. Select either:
        • Service project HelloAzure
        • or Web Role project HelloAzure_WebRole
      3. In Eclipse menu-bar, select Windows Azure menu.
      4. In Windows Azure menu, select Run in Development Fabric menu-item.
    2. or, From Project menu...
      1. Open PHP Explorer view
      2. Right-click either:
        • Service project HelloAzure
        • or Web Role project HelloAzure_WebRole
      3. In Project menu, select Windows Azure menu-item.
      4. Windows Azure menu-item, select Run in Development Fabric cascading menu-item.
  4. Upon initiating deployment of Web Role, the contents of the Web Role project is bundled into the Service project.
    This bundling is hidden from PHP Explorer. To view this bundling, then:
    1. In either Explorer or command-prompt, go to the current workspace directory
    2. Note that Service project HelloAzure has a new directory ServiceDefinition.csx, which contains this bundling.
  5. When service begins:
    • Default browse should open and present the defaultDocument at the next available port, typically at URL http://127.0.0.1:81/index.php
    • Explorer should open to workspace folder of Service project HelloAzure.
  6.  Note:
    This will show you the roles and ports that were requested and issued. If this is the first instance running, you should see a URL of http://*:80 and an IP Address of 127.0.0.1:80. When you execute a Windows Azure service, it will try to allocate the port specified in the ServiceDefinition.csdef file. If this port is not available, the next available port is used.

  7. View Development Fabric UI again:
    1. Expand the tree on the left panel to see the WebRole instances.
    2. As set within ServiceConfiguration.cscfg previously, note that in the left-panel that there are now 2 Web Role deployment instances.
    3. In the right-panel of the UI, this shows a deployment log for each instance.
  8. To stop Web Role deployments, either:
    1. Within left-panel Development Fabric UI
      1. Right-click service HelloAzure
      2. Select menu-item Remove
      3. Note that both deployments have been deleted from the development fabric.
    2. or, Right-click its icon in the system tray and select Shutdown Development Fabric service

 


 

Task 4 — Deploy to remote Windows Azure Cloud

 

In this task, you will run your service remotely on Windows Azure using a Windows Azure Storage Account.

 

 Note:

This task requires that you to have a developer account.

To register for an account, please visit:  Account — Windows Azure Platform.

 Note:

This task does not present a thorough presentation of deploying Service Packages to Windows Azure Cloud.

This task only presents a need to know based upon using Eclipse for Windows Azure.

For a thorough tutorial on deploying Service Packages, read:  Deploying a Service on Windows Azure

For Eclipse for Windows Azure users, in the tutorial ignore the prerequisite to read Visual Studio walkthrough since it pertains to C# Service Packages.

  1. To deploy to the Windows Azure Cloud, you need to create a Windows Azure Service Package.

    There are two ways to create a Service Package and deploy this package to the Windows Azure Cloud:

    1. Manually Create & Publish

      Here the creating and publishing or Service Package are separate steps.

      This process can be performed either of the following ways...

      1. From Eclipse menu-bar...
        1. Open PHP Explorer view
        2. Select either:
          • Service project HelloAzure
          • or Web Role project HelloAzure_WebRole
        3. In Eclipse menu-bar, select Windows Azure menu.
        4. In Windows Azure menu, select Package Application menu-item.
        5. To open Windows Azure Portal...
          1. In Eclipse menu-bar, select Windows Azure menu.
          2. In Windows Azure menu, select Launch Windows Azure Portal menu-item.

            This action will open a portal to Windows Azure, which will be gone in more detail later in this lab.

      2. or, From PHP Project pop-up menu...
        1. Open PHP Explorer view
        2. Right-click either:
          • Service project HelloAzure
          • or Web Role project HelloAzure_WebRole
        3. In PHP Project pop-up menu, select Windows Azure menu-item.
        4. Note with Windows Azure menu-item, the cascading menu-items are the same.
        5. Repeat same steps as in previous Eclipse menu-bar as if within Windows Azure menu.
    2. Combo Create & Publish

      Here the creating and publishing or Service Package are combined into a single action.

      This process can be performed either of the following ways...

       Note:

      No Combo does not included fries or soft drink!

      • From Eclipse menu-bar...
        1. Open PHP Explorer view
        2. Select either:
          • Service project HelloAzure
          • or Web Role project HelloAzure_WebRole
        3. In Eclipse menu-bar, select Windows Azure menu.
        4. In Windows Azure menu, select Publish Application to Windows Azure Portal menu-item.

          This action will open a portal to Windows Azure, which will be gone in more detail later in this lab.

      • or, From PHP Project pop-up menu...
        1. Open PHP Explorer view
        2. Right-click either:
          • Service project HelloAzure
          • or Web Role project HelloAzure_WebRole
        3. In PHP Project pop-up menu, select Windows Azure menu-item.
        4. Note with Windows Azure menu-item, the cascading menu-items are the same.
        5. Repeat same steps as in previous Eclipse menu-bar as if within Windows Azure menu.
  2. Wait for Service Package to finish being created.
  3. When finished, the build results will be presented in two ways:
    1. Explorer will open Service project HelloAzure workspace folder.

      Note the newly create additions to this project...

      • folder ServiceDefinition.csx
      • file HelloAzure.cspkg
    2. and in the Service project HelloAzure
      1. Open PHP Explorer view
      2. Refresh Service project HelloAzure
      3. Included is a new Service Package labeled HelloAzure.cspkg
      4. Note that the new folder ServiceDefinition.csx is purposely hidden.
       Note:

      In the deployment within Windows Azure portal, both of these files will be requested:

      • Service Package file — HelloAzure.cspkg
      • Service Configuration XML file — ServiceConfiguration.cscfg

       Note:

      What is a Service Package?

      • It is what contains the Service Definition for your Cloud Service along with the content and binaries for each of the roles.
      • Service Definition is defined within Service project's XML file ServiceDefinition.csdef.
      • Service Package file contents are zipped and encrypted, and delivered as a file type .cspkg.

  4. When toolkit finishes creating Service Package, it opens default browser to Windows Live Sign-In in order to access your Windows Azure account.
  5. After sign-in, you are redirected to Windows Azure Portal
  6. Select deployment to Staging service.
  7. In Staging Deployment page
    1. From Service project HelloAzure workspace directory, browse to provide:
      • Application PackageHelloAzure.cspkg
      • Configuration SettingsServiceConfiguration.cscfg
    2. Set Service Deployment NameHelloAzure
    3. Select Deploy button and Staging begins copying over the two files for HelloAzure deployment.
  8. In Staging page, after deployment is Allocated, select Run button.
  9. In Staging page, after deployment is Started, select Web Site URL link.
  10.  Note:

    Note in the bottom right-hand corner that the number of deployments are 2.

  11. Note now within the Staging Cloud the defaultDocument index.php is running.

 


 

Task 5 — Cleanup

 

In this task, you will clean up worked performed on Windows Azure.

 

 


 

Summary

 

In this lab, you have learned how to...

 

  1. Create a simple PHP Windows Azure Web Project.
  2. Build and Run PHP Windows Azure Web Project within the Development Fabric.
  3. Deploy and Run PHP Windows Azure Web Project within the Windows Azure Cloud.
  4. Clean up PHP Windows Azure Web Project within:
    • Eclipse
    • Development Fabric
    • Windows Azure Cloud

 

Good job!! You are done with this Lab.