New Windows Azure SDK for PHP Feature: RunPHP (on Windows)

If you are developing PHP on Windows for use on Windows Azure, there is a fancy new feature which may catch your attention. First things first, let’s run through the basics of installing the Windows Azure SDK for PHP in order to set up your environment to get ready for PHP development for Windows Azure.

This new feature is part of the Windows Azure PowerShell and Windows Azure Emulators components which is downloadable through the Web Platform Installer.

Install Windows Azure PowerShell and Windows Azure Emulators for PHP

  1. Open Web Platform Installer via the Windows Azure PowerShell and Windows Azure Emulators deep link.
  2. Click Run.

    image

  3. Accept UAC prompt.

    image

  4. Click Install.

    clip_image001

  5. Click I Accept.

    clip_image001[6]

  6. Go to the kitchen and grab a cup of coffee.

    clip_image001[9]

  7. Click Finish.

    image

How To: Use RunPHP to test a PHP Application on Windows

In order to understand how to use runphp, let’s quickly build a sample PHP application to show off the functionality of runphp.

Now that we have a simple application set up, let’s open a command prompt to use runphp. I will use Windows PowerShell to execute commands, in order to use runphp, PowerShell will need to be run as Administrator.

To run PowerShell as Administrator, right click on the PowerShell icon and select Run as Administrator.

Navigate to the path which contains your application, then execute the command runphp.

image

There are a number of things going on when executing RunPHP, let’s enumerate the high level steps:

  1. Copies an apphost.config file to the current directory
  2. Runs appcmd.exe from IIS Express
    1. Creates a new Website based on the current directory
    2. Configures a HTTP Handler to map *.php files to php-cgi.exe interpreter
  3. Starts IIS Express and binds the website to an open port.

To view and test your website, open a browser visit the localhost address with the appropriate port which the website was bound to during the runphp process.

http://localhost:8080

Once you finish testing, you can shut down IIS Express by opening the PowerShell window and pressing the ‘Q’ key.

Now that you’ve finishing testing your application on your local machine, you can deploy to Windows Azure Web Sites.

Application Frameworks Now Part of the Windows Azure Web Sites Gallery

A recent addition to the Windows Azure Web Sites Gallery has me very excited, support for installing Web Application Frameworks. Installing a Web Application Framework from the Windows Azure Web Sites Gallery provides the benefit of speed and simplicity during setup by means of implicit configuration for Windows Azure Web Sites.

Let’s take a look at how we can set up Django, a Web Framework for Python applications, using the Windows Azure Management Portal.

Setting up Django on Windows Azure Web Sites

This article makes the assumption that you already have a Windows Azure Subscription. If this is not the case sign up for the 90 day free trial of Windows Azure.

  1. Log into the Windows Azure Management Portal.
  2. Click on the + New button
    drawer-waws-new
  3. Select Compute > Web Site > From Gallery
    drawer-waws-fromgallery
  4. Select App Frameworks
    gallery-appframeworks
  5. Click Next
    gallery-appframeworks-django
  6. Click Complete
    waws-django
  7. Click Browse
    drawer-waws-browse
  8. Start Building!

    Did you know there are Python Tools for Visual Studio?

    waws-django-works

Why is this useful?

Having these packages installable from the Windows Azure Web Site Gallery ensures that you’re receiving a great experience when using the Application Framework of your choice. Once the site is configured, simply download the files using FTP to begin development, or upload your application specific files from your local installation of the same framework.

Released: Windows Azure Training Kit – April 2013

Scott Guthrie announced the General Availability of Windows Azure IaaS features which includes both Windows Azure Virtual Machines and Windows Azure Virtual Network. This was paired nicely by a post by Bill Hilf highlighting some customer experiences using Windows Azure Infrastructure Services.

It is my pleasure to announce the April 2013 release of the Windows Azure Training Kit.

Windows Azure Training Kit Home

In this release

There have been a number of improvements in this release alongside the refresh to the Infrastructure Services content including:

  • New Presentation: Windows Azure Mobile Services and Android
  • New Lab: Windows Azure Mobile Services and Android
  • New Lab: Windows Azure Mobile Services and Windows Phone
  • New Presentation: Introduction to Windows Azure HDInsight Service
  • New Lab: Introduction to Windows Azure HDInsight
  • Updated ITPro Content + Agenda
  • Updated Presentations for new feature support Windows Azure Overview, Windows Azure Web Sites, Windows Azure Virtual Machines & Windows Azure Mobile Services.

Release Notes

Fix for WordPress Plugin Update Issues on Windows Azure Web Sites

Good News!

In a recent service update to Windows Azure Web Sites, the Windows Azure Web Sites team has updated the version of Wincache for PHP 5.3 sites to WinCache 1.3.4, which resolves this issue!

Screen Shot 2013-04-04 at 8.58.48 AM

Screen Shot 2013-04-04 at 8.58.19 AM

A while back I posted an article called Workaround for deleted folder still exists in Windows Azure Web Sites, which talks about how to get around an issue specifically with WordPress plugin upgrading. Recently, on twitter there have been a few people running into this issue, so I thought I would go into a little bit more detail on the issue and how to work around it, permanently.

The Cause of the WP Plugin Issue

In order to dig to the root of the problem, let’s take a few steps back here and get a little bit better of an understanding of the different pieces at play.

PHP

PHP is an interpreted language, simply put it is not compiled into machine code, but instead read and executed step-by-step by an interpreter in this instance, the PHP runtime.

This means that every line would need to be read, interpreted and executed on each request. Which in computer science we understand is not very efficient. For this reason PHP can employ caching to avoid parsing every instruction on each request, instead it stores a certain amount of interpreted instructions in shared memory.

IIS

It’s no secret that Windows Azure Web Sites leverages IIS as it’s Web Server. IIS uses FastCGI to interact with the PHP Interpreter. With the Web Server being able to interact with an interpreter, we have the means to serve up PHP code on IIS. As stated above, PHP can leverage a cache in order to avoid parsing each line of a script, enter WinCache.

WinCache

WinCache is installed and enabled by default for PHP Runtimes maintained by the Windows Azure Web Sites team.

WinCache is a caching system which can be enabled for PHP application which run on Windows  leveraging IIS. This is done by Installing WinCache, then adding a reference to php_wincache.dll from within your php.ini file.

 

By default, Windows Azure Web Sites has PHP 5.3 installed with WinCache 1.1.

Now that we have a better understanding of the different pieces involved, let’s take a closer look at the issue at hand.

There is a bug in WinCache 1.1 [Bug #59352] which causes a lock on a folder which isn’t released until IIS is restarted, which is why this workaround is effective at fixing the issue.

How to Resolve the Plugin Updating Issue

The resolution is fairly simple. The bug has been fixed in a newer release of WinCache (version 1.3 which works with PHP 5.4).

Recently, PHP 5.4 was enabled in Windows Azure Web Sites making the fix as simple as following these steps to Enable PHP 5.4 in Windows Azure Web Sites.

Happy Coding!

Windows Azure Training Kit – December 2012

Good News! The world didn’t end, which is good for two reasons, first we’re all alive, but also my team has been working hard to provide you another great Windows Azure Training Kit release.

What’s new in this release?

Back in October, you may have heard of a massive on campus Microsoft event known as Build. Build was a great event filled with an absolutely everything you need to know about Windows 8, Windows Phone 8 and Windows Azure Development. If you haven’t already done so, check out the day 2 keynote which highlights all of the news around Windows Azure.

In this release we’ve packaged up the day two Keynote demos for you to be able to look at the code or deliver a similar session using the very same demos.

Event Buddy Demo

eventbuddy-session-list

In this demo you will start with a disconnected application that manages events and sessions to later connect it utilizing Windows Azure Mobile Services to provide structured storage for events and sessions. In order to use authentication within the application, you will add Twitter (or Facebook) to your application and services. Following this you will upload session decks to SkyDrive and finish by sending Live Tiles using push notifications every time an attendee rates a session.

BUILD Clips Demo

upload-video

In this demo, we will show how to build and deploy an ASP.NET web site that enables users to browse, play, and upload their own personal videos. We will then extend the web site to include Web APIs that power a Windows 8 experience. Finally, the web site project will be deployed to Windows Azure Web Sites and scaled using multiple paid shared instances.

Windows Azure Mobile Services – Scheduler

We have updated the Windows Azure Mobile Services Presentations, Demos and Hands-on Labs to include the new scheduler functionality. If you want some more information about the new scheduling functionality in Windows Azure Mobile Services, check out Scott Guthrie’s post.

Updated Repositories

You can download the offline training kit (Windows only) or grab the files from GitHub.

Provisioning a MySQL Database from the Windows Azure Store

The Windows Azure Store is available as part of the Windows Azure Management Portal, a convenient resource for all of your Windows Azure needs, which can be accessed from a variety of Devices including your favorite iDevice, Surface, Windows Phone, Mac or PC.

At the time of writing, the Windows Azure Store is currently only available in the US.

Click on the + New in the Windows Azure Management Portal Taskbar, then select STORE.

CustomCMS-Store-TaskbarDrawer

The Store opens in a modal dialogue, either scroll down or filter to APP SERVICES to find ClearDB MySQL Database, then click the [next] arrow.

CustomCMS-Store-AppService-ClearDB

Select an appropriate database size (or stay with the Free plan and upgrade later once the site is live) and select the Subscription to charge. Provide a name for the Database (can be left with the default, a name will be assigned for automatically), select the region to provision the database in (whenever possible, try to provision the Web Site and database in the same region to avoid latency). Click the [next] arrow.

CustomCMS-Store-ClearDB-Create

The following screen will provide an overview of the monthly charges of the new MySQL Database. Be sure to review the terms of use and privacy statement, then click the [purchase] checkmark.

CustomCMS-Store-ClearDB-Purchase

After the Add-on has been provisioned, click on the Connection Info button in the Taskbar.

CustomCMS-Store-ClearDB-ConnectionInfo

Copy the connection string for use in your application. Alternatively, a newly created database can be added as a Linked Resource to an existing Windows Azure Web Site, the credentials will be surfaced under the connection string section of the CONFIGURE tab.

Brian Swan has an interesting solution for parsing a connection string from the connection string settings found in the CONFIGURE section of a Windows Azure Web Site in his blog entry getting database connection information in Windows Azure Web Sites

CustomCMS-Store-ClearDB-ConnectionInfo-Details

Stay Cloudy my Friends…