Documente Academic
Documente Profesional
Documente Cultură
Introduction
You can run PHP (as well as other CGI apps) on IIS7 with high performance and reliability thanks to FastCGI.
CGI is a protocol that defines how web servers launch an executable resulting from a request, pass it
arguments and return the dynamic response. You have been able to host CGI applications in IIS in the past,
however there have been challenges prior to FastCGI. As it turns out, the challenge is that there are certain
modules (in PHP, for instance) that are not thread safe. For that reason, IIS traditionally spun up a new
process for each request. This provided the reliability necessary in the face of non-thread-safe modules.
However, the performance suffered due to the cost of spinning up all of these processes. Enter FastCGI. It
guarantees that each process will handle 1 request at a time (providing the reliability), but it allows for process
reuse by maintaining a pool of processes.
While installing PHP on IIS7 wasnt overly complex in the past (see this article if you want the details) we now
have the Web Platform Installer that makes installing FastCGI, PHP and much much more a breeze.
Now, just because you can host PHP on IIS with reliability and high performance, it doesnt necessarily mean
you should. You need some reasons, right? Well, in this post, I will illustrate how to install PHP and FastCGI
on IIS7 easily and illustrate one of many reasons you will want to: The UrlRewrite Module. This module allows
you to easily create SEO-friendly Uris for your application. Lets get to it.
Screencasts
You can see screencasts on YouTube of the topics in this post here:
2.
Click Run (If you get a security warning, click run again)
3.
The Web Platform Installer is now installed. You will see the UI, where you can choose items to
install. Feel free to close this. You can re-open it at any time.
Open the Web Platform Installer 2 Beta (if you closed it)
2.
Under Web Platform, choose Web Server. Select the following items to install
Static Content
URL Rewrite
CGI
3.
o
Under Web Platform, Choose Frameworks and Runtimes. Select the following item to install
PHP 5.2.9-2
4.
Click Install
5.
6.
2.
3.
Copied the TestPHP directory under my new demos directory. (if you cannot seem to copy in your
virtual hard disk, make sure you may need to install the virtual pc additions)
4.
Open IIS
allows you to define simple rewrite maps (your basic from > to mapping). I would guess that this will be used
pretty commonly when creating search-engine-friendly URLs. Lets take a look.
1.
Open up IIS and click on your default web site. Then double-click on Url Rewrite
2.
Now we want to create our map. Click on the View Rewrite Maps link on the right side.
3.
4.
5.
Remembering that Virtual Directory name was TestPHP and our catalog page was called
catalog.php. The URL to our page is: http://localhost/TestPHP/catalog.php. We also had a page called
contactus.php (Urlhttp://localhost/TestPHP/contactus.php). These are pretty ugly Urls. The extension
php means nothing to the general public. Perhaps we want the Urls to look more
like http://localhost/catalog and http://localhost/contact. Lets add the following 2 rules:
6.
Now we need to add the rewrite rule that uses the map. Click Add Rules
7.
8.
Leave the rule action set to Rewrite. Under the Choose the rewrite map section, choose the map
you created earlier. Mine was named PHPTestMap. Click OK
Test It
Now we can type in our friendly URI into the address bar of our browser. Nice.
Conclusion
As you can see, the Web Platform Installer makes configuring PHP to run on IIS a simple task. You can also
see the power of the IIS pipeline. There are a wide array of modules like the UrlRewrite module that you can
take advantage of.