Tools & Code: The Black Art of Installing PHP under Microsoft IIS (5.1, 6.0, 7.0)

You would think that one of the most popular dynamic languages in the industry would have a rather straight-forward process of being installed in a Windows environment with the capability of running under IIS. The disappointing news is that PHP is a literal brain-crushing, mind-blowing, nightmarish experience when it comes to this implementation scenario.
Why? More than likely because PHP was never really designed to run under Windows and is more at home in the Linux world. However, it is now in Windows environment and getting increasingly stronger in it on a daily basis.
One could ask, why a technical site devoted to .NET technologies is suddenly publishing an article on PHP and the answer is fairly straight-forward. If you develop web-sites, even if you are a hard-core .NET professional at some point you are going to run into PHP. And since I have found myself in this very position recently I want to get the information out before I completely forget it…
In the .NET world we already have Phalanger, which is a Microsoft sponsored project for PHP.NET and there is also “Iron-PHP” along with an add-on for Visual Studio if you prefer to remain in that environment.
A lot of Internet web-sites are developed using this tool and there is no sign of this trend abating since it is not only free to obtain but works with all the major components in the web world such as databases.
However, getting it up and running under IIS is still sort of a “Black Art” that I hope this article will make a little easier to handle.
So let’s begin…
First and foremost you have to make a decision if you want to run PHP with plain old CGI processing or the newer FastCGI option. Depending on how your system has been configured, such as those you may be using at your place of employment, you may not be able to install FastCGI and PHP along side with it.
If you install FastCGI and your PHP installer throws up an error during the install process that states that the PHP package may be corrupted, this is a sure sign that your FastCGI implementation on that machine is not compatible with the PHP installation. This has nothing to do with PHP but with the underlying configuration of your machine.
If you are comfortable that you can install FastCGI, go here to obtain the Microsoft version for IIS 5.1 and 6.0… http://www.iis.net/expand/fastcgi
Before you install FastCGI you may have to install the Microsoft Web Platform Installer first. Simply download it from the link noted above to a directory on your machine and execute the installer. Than you can go back to the web page above and begin the FastCGI installation process.
For Vista users you can find a similar article here… http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/. And for both Vista and Windows-7 users, the following article applies… http://technet.microsoft.com/en-us/library/cc753077%28WS.10%29.aspx
Since FastCGI is already an installed component with Vista and Windows-7, these articles at the links above will describe how to make use of it.
For those of us who have yet to upgrade from XP, we have just as much work to do with the addition of installing the FastCGI component if we elect to use it.
Once installed, check to make sure that it was done successfully by checking for the fcgiconfig.js file in your “inetsrv” directory, which can be found in “Windows\System32\inetsrv”. If its there you can proceed. There should be no problems with installing the FastCGI component but checking to make sure is just a good practice.
Now we need PHP itself. Head on over to the following link and make sure you download the “non-thread-safe” version of PHP of the Windows installer… http://www.php.net/downloads.php. According to one document I came across the same holds true for Vista and Windows-7 users. You can review this document at http://www.hauser-wenz.de/s9y/index.php?/archives/280-Installing-PHP-on-Windows-7.html which is a guide written up for Windows-7 installations.
For Windows Vista, this article will apply… http://www.mattsilverman.com/2009/03/install-php-on-windows-vista.html
Ok… Now for the PHP installation….
One thing to take note of. PHP does not like directory names with spaces in them. So don’t use them! As a result, don’t install PHP into “Program Files\PHP”. You will most likely have issues either during the install or after it. The common recommendation is “C:\PHP” for your installation. It is a rather safe bet. However, you can install PHP to any directory of your choosing. Just make sure there are no spaces anywhere in the path.
Once installed, you will find your “PHP.ini file in the root installation directory (ie: “C:\PHP”). You now have to make a few minor updates to this file. Here they are…
Under CGI:
- fastcgi.impersonate = 0
- fastcgi.logging = 0
- cgi.fix_pathinfo=1
- cgi.force_redirect = 0
Under FastCGI
- fastcgi.impersonate = 1
- fastcgi.logging = 0
- cgi.fix_pathinfo=1
- cgi.force_redirect = 0
If you are using FastCGI than you will also have to run the following script to get it initialized properly for IIS…
cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" ^ -extension:php -path:"C:\PHP\php-cgi.exe" (see the article at the end of this piece… “PHP – Miccrosoft IIS 5.1 and IIS 6.0”)
Before running the script make sure you change the path name to where your php-cgi.exe module is located.
Next, you should add PHP default document to IIS as “index.php” via your PHP virtual site’s “Properties” option…
![]() |
And finally, you will have to add the “.php” extension mapping to your PHP virtual directory. And this is a critical implementation. Without it, your PHP scripts simply will not run.
![]() |
Of course, when you try to do this in XP you will find that you will be unable to save your new mapped extension. You will immediately think this is a permissions issue. It isn’t but merely one of those undocumented features by Microsoft to drive technicians insane. See the following article for the complete work-around for this annoyance.
| http://support.microsoft.com/kb/317948 |
If you are going to use FastCGI and you have run the initialization script successfully along with the rest of the steps outlined, you should now be able to run a PHP script file under IIS. If you are using just CGI than the initialization script is not part of the process.
Now save the following script to your PHP projects directory…
<?php
echo “test”;
?>
Open up your browser and access this script via a URL (http://…). You should see “Test” appear in the browser’s display. If you do… you’re set to go…
Now that you have gotten PHP installed, what do you do with it? Creating PHP scripts in a text editor is fine if you are a hard-core UNIX\Linux aficionado. However, for the rest of us who have to get work done, an IDE is a far superior choice. The problem is that most PHP IDEs are rather useless or overly expensive since this is still rather a niche market.
However, the one IDE that stands above all others and will give you a completely professional environment is “Netbeans”. “Netbeans” will provide you with everything you need to develop robust PHP web applications, including a debugger. And the best part is that it is completely free.
Since “Netbeans” was originally developed for Java and has since added a number of dynamic languages to its platform, you could download the entire package if you are interested. However, you don’t have to. All you need is “Netbeans-PHP”, which is a subset of the entire platform.
You can download a copy of Netbeans at http://netbeans.org/downloads/index.html
The image below shows you the download option you should select at the Netbeans site…
|
Black Falcon
| Installing PHP To Run On IIS 5-6 | http://www.mediafire.com/file/uneleyy1mhd/Installing PHP To Run On IIS 5-6.doc |
About this entry
You’re currently reading “Tools & Code: The Black Art of Installing PHP under Microsoft IIS (5.1, 6.0, 7.0),” an entry on TECH NOTES
- Published:
- January 26, 2010 / 7:13 pm
- Category:
- Tools & Code


No comments yet
Jump to comment form | comment rss [?] | trackback uri [?]