This is one of a series of blog posts about my experience competing in the European WinPHP Challenge 2009. Sponsored by iBuildings, Microsoft and Leaseweb, competitors are asked to build a PHP app for Windows Server 2008 and IIS 7 to showcase the FAST in FastCGI. The winner gets travel and tickets to Microsoft MIX 2010 in Las Vagas in March. My entry is “Give It A REST”, a SOAP <-> REST gateway.
When it comes to software development, I’m old fashioned. I’m a firm believer that you should develop and test on the platform that you’re going to ship your code for. And that means getting Windows Server 2008 installed somewhere convenient. My primary test case for this step is to be able to publish the output of phpinfo() at http://localhost/phpinfo.php via FastCGI on IIS 7.
As it has been over 18 months since I last used Windows Server, I hope my experiences prove helpful for anyone else going through this for the first time.
- Getting Windows Server 2008 Installed
- Installing IIS 7
- Downloading PHP 5.2.9 for Windows
- Choosing A PHP Install
- Creating The Phpinfo File
- Testing The Phpinfo File
- Next Steps
Getting Windows Server 2008 Installed
Convenient for me means VMWare Fusion running on my MacBook Pro. My laptop is my main machine, and I’m too mobile to make software development via Remote Desktop practical. Thankfully, I have a Windows Server 2008 license which the folks at Microsoft dropped into my hands at the recent PHP UK 2009 Conference. But what I am short of is disk space. (Last week, I replaced my MacBook Pro’s hard drive with one of those very nice Samsung SSD’s. Actually, “nice” doesn’t remotely do it justice, but what you get in performance you lose in capacity 🙁 )
It took three attempts to get Windows Server 2008 up and running under VMWare Fusion. First attempt failed because the internal DVD drive couldn’t read the install media. I suspect the DVD drive is faulty, although the install media is somewhat scratched fresh out of the packaging. Second attempt failed because VMWare Fusion crashed. I’ve never seen Fusion crash before, so that was entertaining. Third time lucky, up and running …
… and waiting for the inevitable critical updates to download and install. And then the next batch. It’s an unavoidable process, no matter which OS you choose, to be fair, but it would be less wearying if Microsoft batched up the fixes into service packs much more frequently, in order to save time and reboots. (This blog post is particularly verbose because I have plenty of time waiting for things like Windows updates and other downloads. Future posts will be much shorter!)
So, a minimal installation of Windows Server 2008 has taken up 9.44 GB of space so far, leaving me with just 6 GB of space left on my computer. With IIS 7, Visual Studio and SQL Server still to be installed, plus a PHP IDE, I can see that this is going to be a problem. (By contrast, my Ubuntu desktop install, all in, weighs in at only 7.7 GB of used disk space). I might just have to archive my CentOS server test VM for the duration.
Installing IIS 7
Next step – get IIS 7 installed. Hrm … it doesn’t appear on the list of features that Server Manager knows about. But it doesn’t appear to be installed yet either. Where the frack is it? Answer: Windows Server 2008 uses the concept of roles. Pop into the roles section of Server Manager, and you’ll find IIS 7 there. Click through to the ‘Next’ page to go through the Web Server options in detail, and … where is FastCGI? There’s no mention of it at all.
It seems to be bundled with the CGI option. Perhaps a future update from Microsoft could update the description to mention that? Folks used to a Linux platform are also used to having different web server modules for CGI and FastCGI features.
Downloading PHP 5.2.9 For Windows
Before we can configure IIS 7 / FastCGI, we need a copy of PHP for Windows. I thought that it might save time to simply download Zend Server CE for Windows and see how that went. Unfortunately, when I checked this evening, the Zend Server downloads page didn’t list any downloadable packages for Windows, so that wasn’t an option. (Update: the downloads work now. Many thanks Zend).
Not a problem, thinks I … I’ll just download the pre-built PHP for Windows binaries from www.php.net.
Until now, I’ve resisted talking about how annoying the infamous User Account Control (UAC) feature of Windows Vista / Server 2008 is. I don’t want these blog posts to be a review of Windows Server. But as annoying as it quickly becomes, UAC is nowhere near as annoying as the Trusted Sites feature of IE. Especially because this feature stops you from downloading the PHP for Windows binaries from www.php.net. It doesn’t ask me whether I would like to allow the download. It just refuses to download the ZIP file that I have clicked on, presumably because www.php.net actually sends back a redirect to a local mirror.
I couldn’t quickly spot a way to disable the Trusted Sites feature of IE (the controls are disabled in IE’s Options dialog box). Not a problem, thinks I; I’ll just download Firefox and avoid using IE … Guess what? The Trusted Sites feature of IE stops you downloading Firefox too … again, presumably because the download link on Mozilla’s page sends back a redirect to another server. (Mozilla might want to do something about that; they must be missing out here).
The way around it is to go into Security Manager, and down on the right hand side of the initial page is a link to Configure IE ESC. Click on that, then you can switch Trusted Sites off for administrators or all other users. It would have been much better if the UI for IE told me about this, or even offered me a click through to the feature.
I can understand where Microsoft are coming from: best practice for avoiding infections of malware and viruses from the ‘net is to avoid using IE on your servers at all. It’s a consequence of putting a desktop environment on a server (you’d never find a good Linux sysadmin putting a desktop environment onto a Linux server), and a legacy of that environment being Windows. But, for a development environment, it’s reasonable to switch this feature off, so I did.
And then promptly downloaded Firefox 🙂 Apart from seeking an escape from the annoyances of IE, there are two very good reasons for ditching IE for Firefox. Firebug, and FirePHP. I intend to use both as part of this competition.
With Firefox installed, I re-enabled IE ESC, and then promptly forgot about it and IE. Forever. When will Microsoft learn that a good UI can make someone an advocate, and a bad UI (like the one around IE ESC) can make someone a detractor?
Choosing A PHP To Install
php.net provides two different bundles of PHP for Windows for download. You can download a ZIP file, and install the binaries yourself, or you can download a nice Windows installer, and let it do all the work for you. When I used to do this sort of thing on a regular basis, I used to build PHP on Windows from source, so I thought it would be interesting to look at the Windows installer first.
And it’s quite nice, I have to say. It provides the option to configure IIS with FastCGI for you (which sounds like it’ll save a lot of hassle … will that be famous last words? 🙂 ). On the down side, it doesn’t support installing multiple copies at once (how are you supposed to test your code against new releases of PHP if you can’t install multiple copies on the same dev box?), and by default it has every PHP extension marked to not be installed (which might trip up quite a few folks).
It also doesn’t ask you which website(s) you want configured to use PHP/FastCGI. This is a common problem with anything on Windows that tries to automate configuration of IIS. This doesn’t matter for development, where you’ll just publish the one website (an IIS website is roughly equivalent to an Apache virtual host), but on production servers publishing multiple websites, this quickly becomes a problem. It would be nice to see Microsoft sponsor someone to create a first-rate installer for PHP for Windows.
Creating The Phpinfo File
With IIS automatically configured by the PHP for Windows installer, all we should need to do to satisfy my test case is to use Notepad to create a suitable PHP script and drop it into the right place, right? After all, I’m deliberately using a user with Administrator privileges because this is a dev box and I don’t want to waste time working around security that this dev box just doesn’t need.
Sigh. Think again.
Notepad tells me that I don’t have permission to save into the wwroot folder (c:inetpubwwwroot, if you’re not sure where it is). Hrm. What’s behind this hold up? Do members of the Administrators group have permission to create files in this folder? Yes. Am I a member of the Administrators group? (You’ll find that in Server Manager, under Configuration -> Local Users and Groups). Yes. Can I save files to the wwwroot folder? No.
In the end, I worked around this by explicitly giving my user full control over the wwwroot folder. I’m not happy about having to do this, but I’ve already lost enough time to dealing with Windows security features tonight.
Testing the Phpinfo File
Although I don’t have a complete PHP dev environment yet, I should now have enough to be able to see the phpinfo page in Firefox, right? Point browser at http://localhost/phpinfo.php. Drum roll please!
Oh dear. 500 internal server error, and a crash dump automatically uploaded to Microsoft. PHP 5 crashed according to the event logs. Oh ffs.
Well, the good news is that (so far) running Windows Server 2008 in a VM isn’t particularly painful, performance wise. I’ve been able to multitask just fine whilst waiting for downloads and updates and reboots and so on. This is mostly down to the Samsung SSD, as my machine certainly doesn’t have enough RAM to do this when paging out to a traditional hard drive! It will be interesting to see how well it continues to cope with Netbeans and Visual Studio open at the same time when I actually get to write some code 🙂
The bad news is that, three and a half hours after starting the task, I don’t have PHP/FastCGI up and running on Windows Server. Close, but no cigar.
I’m going to call it a night, and take another look at this on Wednesday. Andi Gutmans from Zend has kindly tweeted me a download URL for Zend Server for Windows. That’s downloading now, and I’ll be switching over to that on Wednesday.
In the meantime, good luck to everyone else in the European WinPHP Challenge. I hope you have more success with your dev environment than I’ve had tonight.