Much like many other developers, I like to live on the bleeding edge, learning new language features, using the latest tools so naturally one of the things I wanted to see in Windows Azure Web Sites is support for PHP 5.4. I’m pleased to be telling you today in this post that support for Bring-Your-Own-Runtime is now available in Windows Azure Web Sites.
Out of the box, Windows Azure Web Sites supports PHP 5.3 as you can see from the snapshot of the portal below. In this article I’ll explain how to enable PHP 5.4 in Windows Azure Web Sites.
Configure PHP 5.4 Handler Mapping in Web Sites
In order to enable support for PHP 5.4 in your Windows Azure Web Site, you will first need to create a Web Site.
If you haven’t already signed up for a Windows Azure account, get a 90 day free trial of Windows Azure which gives you access to 10 free Windows Azure Web Sites.
To create your first site, I would suggest following one of the many tutorials on the Windows Azure PHP Developer Center.
I’ve created my Windows Azure Web Site, What’s Next?
To bring you up to speed, I’ve created a Web Site using Quick Create, using configphp54 as the dns prefix for my Web Site.
Click on the Name of the Web Site [in my case configphp54] to proceed to the Details page for your site. On the details page you will see top level navigation items [DASHBOARD, MONITOR, CONFIGURE, SCALE, LINKED RESOURCES] listed. Click on DASHBOARD.
In order to be able to deploy files to the site, we’ll need to create some deployment credentials, you can create [or reset] your deployment credentials from the quick glance section of the DASHBOARD.
Click on create [or reset] deployment credentials to be prompted with a dialog box to enter your credentials.
Fill out the user name, new password and confirm password to create your deployment credentials or simply the new password and confirm password to reset your password. Now your web site is ready for FTP or Git deployment.
Next, click on CONFIGURE.
At the bottom of the CONFIGURE page you will see a new section called Handler Mappings.
Handler Mappings are a way to map a Fast-CGI script processors to file extensions in IIS. These script processors are typically console applications which means they may be able to accept additional command line switches. To set up a custom handler mapping you are required to set at least 2 of the three values, let’s quickly go into some more details around Extension, Script Processor Path and Additional Arguments.
Extension: This is the file extension which should be mapped to the Script Processor.
Script Processor Path: This is the field which specifies the absolute path to a Script Processor [in our case this will be php-cgi.exe]. The script processor’s binary and configuration files can be located anywhere within the application root directory which can be accessed using the D:\home\site\wwwroot path.
Additional Arguments: If the script processor supports additional command line switches which you may require, you can configure them in the Additional Arguments input box.
We’re only going to fill out the Extension and Script Processor Path to configure PHP 5.4. Enter the following values into the handler mappings section.
After you type each line, click the checkmark at the end of the line to commit the value and add a new row. Clicking on the checkmark does not save the entries, a save button will show up in the command bar at the bottom of the portal.
Script Processor Path
wwwroot is publicly exposed to the internet which could potentially allow remote execution of executable files contained in wwwroot. By default IIS blocks access to the bin directory of any website or virtual directory, which is why it is safe to place the php runtime in the wwwroot/bin directory.
After you are finished, hit the save button that appears in the command bar to commit these settings.
Wait? Where do I get PHP 5.4 for Windows Azure Web Sites?
Before this site will actually work, we need to provide the php54 runtime in the path specified in our handler mappings settings. Download and extract the VC9 x86 Non Thread Safe zip file to the bin directory in your project
Note Your password is the password you typed while creating your deployment credentials above. This password is used for Git or FTP deployment. For WebMatrix, you can use the Publish Profile to load the configuration for a seamless publish experience.
Trust, but Verify… (Thanks Horatio… Yeah!)
index.php file which contains a call to
phpinfo() to the wwwroot folder.
If you browse to the site you will see that the site is in fact running with the latest version of PHP (5.4.7 at time of writing).
PHP does auto-discovery of the
php.ini file by looking in known locations where it is expected to be placed, the first such place it looks is the directory which contains the script processor. This means that you will have access to your own
By Default, the PHP runtime does not have a
php.ini file, it is packed with
php.ini, open the file and search for
fastcgi.logging and remove the preceding semicolon (;) which will uncomment the line
fastcgi.logging=0. FastCGI Logging needs to be disabled (0) in the pipeline or it will return a HTTP 500 when you attempt to execute a script.
With Great Power, Comes Great Responsibility
Now that you own the runtime, you essentially own the experience and the security of the application. Be sure to follow the guidance on iis.net Best Practices for Configuring FastCGI and PHP to ensure optimal performance and security.
Stay Cloudy my Friends