Hello World Azure in PHP

Building on the Windows Azure Command Line Tools blog post, I thought we could kick it up a notch and get PHP running in Azure leveraging the command line tools. The primary thing that we need to do is to copy the PHP bits up with the rest of your deployment and configure the FastCGI handler to know where the PHP interpreter can be found.

If you have PHP installed, locate your directory. Otherwise, download one of the versions from http://windows.php.net/download/. I haven’t personally tested it with every possibly distribution but it should work with all of them up there.

To get started, setup a simple folder structure as before but with the addition of a folder called PHP:


Now copy the contents of the PHP download or your PHP install to the php folder.

Now add a file called index.php to the WebRole directory:

<head><title>Hello World PHP</title></head>

echo 'Today is '. date('Y-m-d') ."\n";


The one other actual difference between the HTML version and the PHP version of this little hello world sample is that you need to add one more file to the WebRole directory called web.roleconfig.

<?xml version="1.0" encoding="utf-8" ?>
      <application fullPath="%RoleRoot%\approot\php\php-cgi.exe" />

On your own IIS server you would call this the web.config but in Azure, it’s called the web.roleconfig.

Now, just like in the other sample you need to set up your Config and Definition files.


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


<?xml version="1.0"?>
<ServiceConfiguration serviceName="Simple" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
  <Role name="WebRole">
    <Instances count="1"/>

Package everything up with cspack.

c:\Project>cspack simple.csdef /copyonly
Windows(R) Azure(TM) Packaging Tool version
for Microsoft(R) .NET Framework 3.5
Copyright (c) Microsoft Corporation. All rights reserved.

And run in the dev fabric with csrun.

c:\Project>csrun simple.csx simple.cscfg
Windows(R) Azure(TM) Desktop Execution Tool version
for Microsoft(R) .NET Framework 3.5
Copyright (c) Microsoft Corporation. All rights reserved.

Using session id 1
Created deployment(31)
Started deployment(31)
Deployment input endpoint HttpIn of role WebRole at

Now you are ready to run and test


And that’s all that there really is to getting PHP running in Azure. Soon I’ll blog about getting a full blown app running in Azure. Stay tuned.

Leave a Reply

Your email address will not be published. Required fields are marked *