Making PHP Applications Great on IIS7

You may have heard about the new interoperability improvements for PHP and Microsoft technologies that Bill Staples blogged about. A few weeks ago, I spoke at PHP|Works in Atlanta and showed off a project I've been working on to demonstrate how PHP applications can take advantage of the new features of Internet Information Services 7.0 (IIS7).

The goal of my project was to enhance a PHP application hosted on IIS7 without changing the PHP code. In other words, the enhancements I would make could be packaged as an additional set of features or configuration steps when the PHP application is deployed to IIS7. However, the PHP application could continue to be deployed to currently targeted platforms, minus the enhancements for IIS7.

imageI chose the Qdig script (qdig-devel-20070210) as the target application for my project. The reason is that I like the simplicity of a self-contained script and the fact that it can be added to an existing application by simply dropping it into a directory containing images. It also makes it easier to explain the enhancements I made without the need to understand the architecture of a larger application. The same types of enhancements can be made to any PHP application whether large or small.

There are several out-of-box IIS features that Qdig can take advantage of by making simple configuration changes with IIS:

Getting Qdig up and running on IIS7 was easy using the instructions documented here. My next step was to enhance the script using some of the new extensibility features of IIS7.

So far I've added several enhancements that make Qdig a great application when running on IIS7.

1. Enabled Forms Authentication and Role Manager

One of the easiest things to take advantage of is the new integrated pipeline to secure your Qdig site with ASP.NET Membership. I used the built-in SQL Express database provider which gives me a membership store for user registration. I also used the same database with Role Manager to add a role for users authorized to update captions in Qdig. Both the membership and role systems use a provider model, which means the data store can be replaced with whatever you want to use.

Now when I click the Admin link for caption editing, I'm prompted with a login page.

imageA0image

image

I can use the new .NET Users and Roles features in IIS Manager to manage the users who have access to my Qdig gallery:

image

Remember, to use these managed modules with PHP, you need to locate them in the Modules feature and uncheck the option to Invoke only for requests to ASP.NET applications or managed handlers.

image

Because Qdig doesn't know about the Roles assigned by RoleManager, I created a quick IHttpModule that executes for every request. If the URL being requested includes the Qdig command for Admin, then the module checks for authorization.

image

2. Extended the Configuration Schema

I added three elements to IIS7's configuration schema to help manage Qdig. The first two I'll use later to help automate deployment of the Qdig script to a new virtual directory. I added the target name of the Qdig script (by default index.php) and a source location to copy a fresh Qdig file from.

The third element allows me to configure the role used to authorize users for caption editing. I can set this system wide or for each website or application.

Here's a shot of the schema file:

image

And the configuration element in applicationHost.config (or a local web.config)

image

3. Extended IIS Manager

Finally, I added several features to IIS Manager to allow website or application owners to deploy Qdig and configure it from the IIS Manager. One benefit of extending IIS manager is that the new deployment and configuration capability will work from a remote computer using the new remote IIS manager over an HTTP connection.

imageA0image

A0

What's Next?

With a just a little work, I've been able to enhance the Qdig application when its running on IIS7. I'll be adding on more features such as integration with the new FTP server to allow image uploads. I'd also like to get all of the Qdig settings, which are currently embedded in the Qdig script, integrated into the IIS7 configuration system. This would allow me to distribute and delegate Qdig settings and deploy the settings across a web farm using IIS7 shared configuration.

Over the next few weeks, I'll be posting more examples of integrating Qdig with IIS7 and the actual code for my example. For now, it's off to Barcelona, Spain for TechEd Europe.

2 Comments

Comments have been disabled for this content.