Wednesday, July 7, 2010

WebMatrix PHP Editor

Yesterday Scott Guthrie announced WebMatrix, a new tool from Microsoft which lowers the barriers to entry for creating your own .NET based website. It features all the newest Microsft treats which Guthrie has introduced over the last week: IIS Express, Compact SQL Server, and Razor.

Tonight, rather than playing with all these new toys, I was able to setup WebMatrix as an IDE for an existing PHP website I manage. A screenshot (clicky, please):



It's pretty, by far the best looking PHP IDE I've tried. And easy to use; everything about it screams simplicity (which is good and bad: no intellisense, no right-click context menu). Still a huge improvement over my previous editor: Filezilla and TextPad :)

Two big complaints: the Publish functionality wasn't working well for me (I update to an ftp site, WebMatrix updates *all* files everytime) and my site doesn't render perfectly in the browser (css-related stuff, not sure if it's an IIS Express).

I did have to go through a bit of pain to get IIS Express to render php pages. Detailed issue below:
  • Trying to load a .php page, I recieved a HTTP 404.3 error: "The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map."
  • The handler is not present! I spent quite a bit of time trying to manually update the .config file (I think I was updating the wrong one - %WebMatrixInstall%/config/applicationHost.config?? Anybody know?) before finding this post which details how to add a php handler to IIS 7.0 and IIS 7.5 (and IIS Express, which is based on IIS 7.5) via appcmd.exe.

And how to fix it:

  • Open a command prompt at your WebMatrix install directory (mine is "C:\Program Files (x86)\Microsoft WebMatrix"
  • For the following command, replace the scriptProcessor parameter with your proper path to php-cgi.exe and run: " appcmd set config /section:handlers /+"[name='PHP_via_FastCGI',scriptProcessor='C:\Program Files (x86)\PHP\php-cgi.exe',path='*.php',verb='*',modules='FastCgiModule',resourceType='Either']" "
  • Do the same with this command: " appcmd set config -section:system.web
    Server/fastCgi /+"[fullpath='C:\Program Files (x86)\PHP\php-cgi.exe']" /commit:a
    pphost "
  • It works (for me)!

All in all, I was very impressed with WebMatrix and IIS Express. I'll be using WebMatrix to manage my PHP site in the future and I hope to play with Razor and SQL Express soon!