Deploying PHP on Windows Azure

I can create and deploy an application on PHP Fog in under 5 minutes from scratch to finish; how hard can it be on Windows Azure?

On PHP Fog I can create a new application, select a framework (e.g. WordPress, Drupal, CodeIgniter, etc), deploy it, setup SSH and git, pull the app, modify it, and redeploy in probably about 5 minutes. If someone already has SSH keys setup and git, that 5 minutes is about 1 minute.

I wanted to see what that experience is like trying to create a “Hello World” application on Windows Azure. So here I am documenting the steps, and my thoughts along the way.

I follow instructions I saw scattered, but provided by Microsoft. Unfortunately they suck at documentation: they write a lot but say very little and there is no single definitive guide.

Step 1: Install PHP

First of all, this is weird. I don’t plan on running my PHP app locally, so why should I setup PHP on this machine. I certainly don’t have to with PHP Fog.

Step 2: Instal PHP Again (and Azure SDK, tools, and Visual Studio)

Turns out I didn’t need to install PHP from the php website, instead, Microsoft provides a Web Platform Installer which installs PHP.

Step 3: Wait on installation

This seems to be taking a while.

Step 4: Set environment variables for PHP

Seems like this belongs in the installation, not as a separate step. Oh well. Here I’m just adding the PHP binaries to the path so I can use it on the command line.

Step 5: Install Azure PHP SDK

This doesn’t come with a nice installer. The PHP + Azure SDK requires that you download a zip, place it in a specific directory, and then I’ll have to set some variables. No installer here :-(

Step 6: Set environment variables for SDK

Same screenshot again, this time to add the reference to the PHP Azure SDK binaries.

Step 7: Run scaffold to create a scaffold

My environment at this point is theoretically setup. I even ran the verification step to ensure it works. Now I need to create my application in the local environment. To create the application I need to run the scaffold tool.

Before I run the tool I am getting a bit frustrated. The simplest PHP application on mac can be created like this “echo ‘<?php echo “hello world”;?>’ > index.php“. But now I have to do a whole bunch of additional work to create the “scaffold” and later the “package”.  I hate having to create all this additional junk to define a package. And if I do, why can’t I just create a single file called config.ini or something.

Turns out this completely failed for me anyway. I got a bunch of errors. I dont’ know what’s up with this. Frankly, I’ve already spent a lot of time and I really don’t want to be diagnosing this.

Step 8: Configure you PHP File

This is ridiculous. I actually have to modify commented out code using a Microsoft syntax. WHY!? This is a terrible programming practice. This should be in a sperate configuration file, not in configuration. Blasphemy. I’m actually surprised by this, Microsoft actually has excellent coding practices and this inappropriate. Comments are human readable, code is for the machine.

Step 9: Plan B, downloading a sample

Since creating the sample app via the scaffolding tool failed, I went to plan B. I downloaded a sample from git-hub.

Step 10: Update my code

Finally! I am a developer and after 2 hours I finally got to coding. WOW!

Step 11: Run locally – Skip

I’m skipping this step because I don’t feel like running this locally, I am just trying to do the minimal work here to get the app onto Azure.

Step 12: Package

I was already frustrated with this concept of scaffolding which is introduced to me, a PHP developer, which is totally unrelated to PHP. Now I have to create a Package. I don’t want to learn this proprietary stuff to get an app running, but I just want to get the app into the cloud, so I’ll suck it up. I was scared that this wouldn’t work since the previous scaffolding command failed. But luckily it worked.

So now I have a package which is ready to be uploaded to Azure.

Step 13: Deploy

Yey, I’m ready to deploy. Just need to select the package and the configuration file (why I have two separate files confuses me.)

Step 14: Wait

This seems strange. I’m started writing this article while I was waiting. At some point I was starting to doubt it was going to deploy. It took something like 5+ minutes. That seems like a damn long time. On PHP Fog it takes us about 30 seconds to spin up new instances. After you have an instance it only takes seconds to deploy modifications.

Step 15: DONE!!!

http://phpfog.cloudapp.net/

Conclusion
I’ve built PHP Apps on PHP Fog, Cloud Control, Pagoda Box, AppFog, Cloud Foundry, Dot Cloud, Orchestra IO, and this is the worst experience for PHP developers by a LONG shot. Microsoft is actually pretty awesome when it comes to the developer experience for developers, as long as you stick to the full Microsoft stack (Visual Studio, Windows, Azure); if you go outside if it, you are in a world of pain.

I’m very tempted to write another article explaining what I think Microsoft would need to do to make Windows Azure attractive to open-source developers.

  • Bswan

    I work at Microsoft and I would love to hear your thoughts on what we need to do to make Windows Azure attractive to open-source developers.
    -Brian
    http://blogs.msdn.com/b/brian_swan

  • Nnnn

    Just a quick thought: I saw you use PHP 5.2. With 5.3 the scaffolder works great. In 5.2 I think you need to enable PHAR support.