[This is a blog post related to the PHP on Azure competition.]
I’m sure everyone blogging about this contest will at some point write a post describing their experiences setting up an Azure development environment, but writing two posts a week is hard, so I can’t pass up an easy topic! Mine won’t be terribly formal since there are plenty of guides out there that already do that, so: from a clean Windows 7 install, here’s a minute-by-minute style guide to getting a PHP on Azure development machine configured. I’m going to try to stay away from as many guides and tutorials as possible to see how intuitive this process is.
The following takes place between 9.43pm and 01.56am on 02/03 March 2011.
The previous two hours involved me creating a new hard drive partition alongside my XP install and installing Windows 7 into it. I’m using the free Enterprise trial for the time being. After booting for the first time, I install some Windows updates and reboot. The next thing I do is open Internet Explorer 8, search for Google Chrome and install it. IE’s come a long way recently, but it’ll have to go a lot further before I use it as my main browser. I write the intro to this blog post, and that takes us up to where we are now.
I go here and download the Microsoft Web Platform installer, a neat utility which allows developers to install both products such as IIS and PHP, and web applications like WordPress and Drupal. Looking through the list I remember that Windows 7 (Enterprise edition, at least) comes bundled with IIS, so I think I’d better install through Windows to avoid confusion.
I go into the add/remove Windows features programs bit in Control Panel and check the Internet Information Services option which installs IIS with the default settings.
I open up IIS Manager, and all seems OK. I hit http://localhost in Chrome and I get the delightful IIS7 landing page. Web server: check. Painless.
I think I’ll add a picture of the IIS7 page since it looks so nice, and it gives me an excuse to try the new Paint application (which I think is a Windows 7 thing, though it may have come with Vista. I’ll never know). Paint’s a lot better these days, that’s for sure.
I run the Web Platform Installer (henceforth WPI) and select the Products tab. There’s plenty of stuff in there that looks cool, but for now I’m only going to bother with the essentials, so I choose:
- SQL Server Express 2008
- Windows Azure command line tools for PHP (sounds like that’ll come in handy!)
- PHP Manager for IIS (I’ve used this in work, it makes configuring PHP for Windows a breeze)
- PHP 5.3.5 for WebMatrix (not sure what the WebMatrix bit is about, but it’s nice to see the latest version of PHP in there)
There’s a whole bunch of other stuff there that looks like it’ll come in handy, but the above should get me to a point where I can get a PHP script running so we’ll start there. I hit install, and see A LOT of dependencies which will also be downloaded. Turns out the PHP 5.3.5 for WebMatrix install is a little bit of PHP, and a whole lot of WebMatrix – and PHP 5.3.5 is already being downloaded as a dependency of the Windows Azure command line tools. I’m a little freaked out, and decide to untick the WebMatrix trojan horse and just try installing PHP on its own for now until I discover that I need anything else.
Since I’m installing SQL Server, I get asked to set a password (I don’t have to, I could use Windows authentication, but I figure it’s safer). I choose a suitably fiendish one.
This could take a while, so I go downstairs for a chat with my wife and a cup of tea.
I come back to a screen notifying me that all programmes but SQL Server installed correctly. I open the install log to find out why, and would you believe it – my password wasn’t strong enough! Lesson learned. OK, another go, this time with a tougher password. I also add in the SQL Server Management Studio application for working with SQL Server which I’d missed the first time round.
It’s taking ages to install SQL Server Management Studio, so I go back and rewrite the intro which somehow is in a completely different tense to the rest of the article. I look at the copy of Strunk and White on my desk and realise I need to read more than the 10 pages of it that I’ve managed to date.
And at that moment, the installer finishes. No error messages this time, which means I’ve got l33t pa55w0rd skillz. Now to check if PHP is working.
I open up a command prompt and type ‘php’ into it. Hit return. Error message – PHP isn’t recognised.
Usually this means that PHP isn’t in Windows’ PATH, so I probably need to do that. Hmm. Where’s the WPI put PHP? I find it under Program Files. Add that to the end of the path variable. Restart the cmd prompt. PHP is now responding, and the version is listed as 5.3.5. Fantastic.
I’m curious as to what modules come bundled with PHP when it’s installed via the WPI, so I’m going to check that out. I could do it through the command line with the -m switch but I also want to check the PHP manager for IIS is running, and configure PHP for IIS at the same time.
I open up IIS and select the default web site, then select the PHP Manager module. It tells me that my PHP configuration isn’t correct, and offers to set the default document for the website to index.php and monitor my php.ini file for changes, both of which are helpful suggestions. I do both. IIS seems to have picked up the correct version of PHP, so all is well in that regard.
The default web site is pointing to C:\inetpub\wwwroot, and it’s got some random stuff in it. I delete both the default web site and the files, then create a new site. I create a new one called ‘localhost’ and set it to respond to ‘localhost’. I try to add PHP file called index.php which outputs phpinfo(), but I don’t have administrator rights for this folder. Grr. I add myself with read / write permissions, and save the file successfully.
I hit http://localhost in the browser, and wow – it’s working. The PHP interpreter, FastCGI as the SAPI – and all with pretty much zero configuration. Take it from someone who spent a good few evenings last year building a LAMP server from source and configuring PHP in Apache – this is impressive. OK, so I’ve done a lot of this before, but having the WPI take a lot of the grunt work away is so helpful. Also I always have to check which version of PHP I need on Windows – is it non-thread-safe? Thread-safe? VC6? VC9? It’s nice having all that uncertainty taken away.
I take a look at the modules list. The usual suspects, nothing too fancy. I’m surprised to see that the Microsoft SQL Server Driver for PHP isn’t on there, I assumed that would be bundled. I think I saw it in the WPI, actually. I’ve a few can’t-live-without modules like PECL HTTP and XDebug that I’ll have to add in due course.
OK, it’s getting late – time to wrap this up. I need to find a ‘my first Azure app’ tutorial on the web and make sure I can run it.
It doesn’t take much Googling to come across this article, which seems to be exactly what I’m looking for. I’m not too bothered about deploying to the cloud just yet, I just want to make sure I can develop on my local machine for now.
I seem to have covered the first few steps already (they’re concerned with the Azure command line tools for PHP which I installed via the WPI earlier – that article could do with an update to notify others in a similar position), so I skip on and open up the Azure SDK command prompt.
I keep following the steps, successfully creating a file and a temporary project. I come to packaging the project with the package.php script, and deploying to DevFabric, and get the following error:
Runtime Exception: 0: Default document “ServiceDefinition.rd” does not exist in Service directory “ServiceDefinition.csx”!
No idea. Google tells me nothing. Maybe I missed something in the earlier part of the tutorial.
OK, looks like I might have needed to start the Compute Emulator. Let’s try that… Oh, and the Storage Emulator too.
Nope, that doesn’t fix it. I’d better re-read through everything in case I missed something.
I read through the package script code to see where things are going wrong. I see quickly enough where it attempts to reference the missing file, leading to the exception, but there doesn’t appear to be a point where the file is actually created. Is it supposed to be copied from somewhere? I can’t see anything obvious and there’s nothing on Google that mentions what that file is or where it comes from.
This isn’t good. My ass is nowhere near Vegas at the moment!
I’m totally out of ideas, and I’m not above begging for help, so I contact Maarten Balliauw (who has published a lot of material on PHP on Azure) via Twitter to see if he’s seen the error before and can point me in the right direction. He kindly offers to put me in touch with someone involved in creating the tools, and in the middle of MVP 2011 festivities too!
Since I’ve followed the instructions in the articles to the letter, I’m wondering if Windows is to blame. I’m noticing other weird behaviour on my machine. Windows suggests folders to me in the command line that don’t exist; it’s been using my external hard drive to store installers from WPI; when I try to restart my machine to see if that’ll cure the problem it tries, and fails, to install Windows updates. Perhaps running Windows on a partition alongside XP wasn’t such a good idea after all. I decide enough’s enough, and go to bed frustrated.
The Next Day
Despite having slept on it and coming back fresh I’m still having the same problems, and am less confident in my installation in general. It’s possible there may be a bug in the Azure tooling, but given I’m having other issues I think the best thing to do is to take the plunge and install Windows 7 onto a dedicated drive, in case there are conflicts arising from sharing one with XP (I don’t see how that could be the case, but strange things are definitely happening).
I’m a little disappointed because things seemed to be going very smoothly right up until the last hurdle. The WPI, with its dependency management, makes it so easy – I’ve since learned I need only to have installed the Azure Command Line Tools for PHP to have got everything else automatically, which is neat.
So I now face my second install of Windows 7 in 24 hours – a task I think even Jack Bauer would blanch at
I’d like to thank Maarten for helping me out when I was seriously fed up. Hopefully after a re-install this problem will go away and I can finally start developing. Fingers crossed!