There has been numerous post on the IIS forum where people have difficulty installing PHP on Windows. There are many reasons for this. However the main issue is that people try to do the installation manually and any manual step is prone to error. It is not a bad idea to do the installation manually but I would suggest to leave that to an advanced user who knows PHP well and has successfully configured it many times. For novice user or people who are just starting using PHP, I am going to talk about an easy way to install PHP on Windows and IIS. This article applies to user running IIS from Windows XP to Windows 7.
Let me introduce you to Microsoft Web Platform Installer. Let's call this WPI in short. WPI is a single stop shop for all the major component installations for IIS. Once you have WPI installed, go to 'Web Platform Section' and click on 'Frameworks and Runtimes'. Click on 'customize'. You can see PHP listed as one of the 'Runtimes'. Select it and say install. And you are done. Yes, that's it. Amazed!!! But trust me it is as simple as this.
Now let's go in detail and see what happens when you say 'Install'. WPI does the following things for you:
- Figure out all the dependent component if any is required. In PHP case, the dependent component is IIS FastCGI.
- See if the IIS FastCGI is enabled/installed or not. The reason I am stating enabled/installed is because FastCGI comes out of the box on Vista SP1+ OS, where as the previous versions of OS release (XP/2k3) FastCGI comes as a separate component which needs to be installed. WPI depending on OS you are running either grabs the latest version of FastCGI or enables it. If FastCGI is already installed nothing is done.
- Now that FastCGI is installed, it runs the PHP MSI (Non thread safe) by passing it as an argument to MSIEXEC.EXE. It also passes additional argument to it like auto configure IIS FastCGI and enable by default popular extensions.
- You have PHP up and running.
Okay, you got FastCGI but what about all the handler mapping and other things. Who does that? This is done by PHP MSI. This is good enough reason to use the PHP MSI. Let me now explain what PHP MSI is doing:
- As explained above one of the switch passed to MSIEXEC.EXE was to configure IIS FastCGI. As part of this PHP installer does two things. One adds the FasCGI handler mapping appropriately and other adds 'index.php' to default document list. Again the command used internally is different for Vista SP1+ OS and OS prior to that, but you are saved of all the pain of figuring out which command to use or how to do it from IIS Manager.
- It installs all the popular extensions. Yes, you don't need to worry about that.
- It also sets some of the critical and useful PHP INI directives. Couple of example include 'max_execution_time' is set to a higher value because some PHP application install takes more time to run the install script and setting it to a higher value ensures that script will not time out. It also sets 'error_log' to a file where all your PHP errors will be logged rather than on the browser. There are few other useful directives which are set. Overall less problem while you are running your PHP application.
- It also sets some of the FastCGI settings like fastcgi.impersonate is set to 1.
So now you know, how helpful WPI is in setting up PHP on your Windows machine with IIS. I would advice people to start using WPI for doing the PHP installation. It's less time-consuming, less error-prone and gets you up and running in seconds.
Before I end this post, I would like to tell few important things:
- The current WPI offers PHP5.2.11. I will explain how to upgrade to PHP5.3 smoothly in another post.
- If you have PHP running as ISAPI already, you will need to uninstall it manually. Uninstall means removing the PHP as well as removing all the handler mapping from the configuration file. I would advise to use IIS Manager to do that rather than doing it manually. In IIS Manager go to 'Handler Mapping' section and remove all the handler for *.php before you continue your installation. This is because PHP MSI doesn't have ability to find out that PHP is configured to run as ISAPI and hence cannot remove it.
I expect this post is going to help people in setting up the PHP environment.
Please feel free to ask any clarifying questions.
Thanks for reading the post.