SALES: 1-800-867-1380

Configure IIS Components in Azure

Updated: October 24, 2014

You can use Startup element to specify tasks to configure your web role environment. Applications that are deployed on Windows Azure usually have a set of prerequisites that must be installed on the host computer. You can use the start-up tasks to install the prerequisites or to modify configuration settings for your environment. Web and worker roles can be configured in this manner.

noteNote
The Startup element is available using the Windows Azure SDK version 1.3 and later.

To configure your service to run a start-up task, you must add the Startup node to the service definition file. The Startup node specifies the task to perform. This is typically a CMD file that contains a script that can be run unattended.

The following code sample shows a startup task that configures an IIS web role by executing a CMD script file.

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="IIS_Demo" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
   <WebRole name="MyWebRole">
      <Startup>
         <Task commandLine="ConfigureIIS.cmd" executionContext="elevated" taskType="simple" />
      </Startup>
      <Sites>
         <Site name="Web">
            <Bindings>
               <Binding name="HttpIn" endpointName="HttpIn" />
            </Bindings>
         </Site>
      </Sites>
      <Endpoints>
         <InputEndpoint name="HttpIn" protocol="http" port="80" localPort="80" />
      </Endpoints>
   </WebRole>
</ServiceDefinition>

When specifying a start-up task, you can choose one of the following execution context values:

  • Limited: Run with the same privileges as the role that is hosting the process.

  • Elevated: Run with administrator privileges.

The following task type values are available:

  • Simple (this is the default value): System waits for the task to exit before any other tasks are launched.

  • Background: System does not wait for the task to exit before other tasks are launched.

  • Foreground: Similar to background, except the role does not restart until all the foreground tasks exit.

noteNote
The commands and batch files for start-up tasks must be saved in the ANSI format. File formats that set a byte-order marker at the start of the file will not process properly.

To support a Windows Azure application, you may need to install additional server components or non-Microsoft packages. In this scenario, you can use the Microsoft Web Platform Installer (Web PI) command line tool to perform the task. Web PI is a tool that makes getting the latest components of the Microsoft Web Platform, including Internet Information Services (IIS), SQL Server Express, .NET Framework and Visual Web Developer easy. Web PI also makes it easy to install and run many free web applications. For more information about Web PI, see Microsoft Web Platform Installer.

For additional information on WebPiCmdLine, see Use the WebPICmd Command-Line Tool.

One common component that users install is the Hypertext Preprocessor (PHP). The following procedure explains how to install PHP for your service. The following procedure assumes that you have created a Windows Azure project with at least one web role. For more information on creating a Windows Azure project with Visual Studio, see Creating a New Windows Azure Project with Visual Studio.

  1. Download the Web PI command line tool.

  2. Extract the WebpiCmdLine.exe, Microsoft.Web.Deployment.dll, Microsoft.Web.PlatformInstaller.dll, and Microsoft.Web.PlatformInstaller.UI.dll files to a folder in your Windows Azure project.

  1. Open the Windows Azure project in Visual Studio.

  2. In the Solution Explorer expand solution.

  3. Left click the web role. Click Add and then click New Folder.

  4. Name the folder startup.

  5. Left click the startup folder. Click Add and then click Existing Item.

  6. Navigate to the folder where you extracted the Webcmdline files. Select the three DLL files and the EXE file and click Add.

  7. In the startup folder select the three DLL files and the EXE file. In the properties pane set Copy to Output Directory to Copy if newer.

In the next procedure you will create the CMD file that will run as a start-up task. The command file uses the Web PI command line installer to install the PHP 5.3.

  1. Open notepad or your preferred text editor.

    WarningWarning
    Text files that are created in Visual Studio are saved by default in a format that includes a byte order mark which makes it impossible to execute them as batch files. If you use Visual Studio to create your command file, use the advanced options menu of the Save File <file name> As on the File to save the file in a format that can be run on Windows Azure. The advanced options menu is accessed by clicking the small rectangle to the right of the Save button and then click Save with Encoding to open the Advanced Save Options dialog box. Use this dialog box to specify the encoding for the file. Unicode (UTF8 without signature) codepage 65001 works for saving command files that run properly.

  2. Copy and paste the following commands into the file.

    md "%~dp0appdata"
    reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d "%~dp0appdata" /f
    %~dp0webpicmdline /AcceptEula /Products:PHP53 >>log.txt 2>>err.txt
    reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d %%USERPROFILE%%\AppData\Local /f
    
    
  3. Click File and then Save As…. Type InstallPHP.cmd and click Save.

  4. In the Solution Explorer expand solution.

  5. Left click the startup folder. Click Add and then click Existing Item.

  6. Navigate to the folder where you saved the InstallPHP.cmd file. Select the file and click Add.

  7. In the startup folder select the InstallPHP.cmd file. In the properties pane set Copy to Output Directory to Copy if newer.

  1. In the solution explorer, double click the ServiceDefinition.csdef to open it.

  2. Locate your web role in the service definition file.

  3. Copy and paste the following XML snippet just before the </WebRole> tag.

    ...
        <Startup>
          <Task commandLine="startup\InstallPHP.cmd" executionContext="elevated" taskType="simple"/>
        </Startup>
    ...
    
  4. Save the file.

The Windows Azure project solution will resemble this when you are finished.

Startup Folder in the VS Solution Explorer

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft