Installing PHP on Windows

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.

Don Raman

13 Comments

  • Microsoft SQL team has come up with new PHP driver for MSSQL. All details are http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx. Also if you have problem with PHP you can use the forum at http://forums.iis.net/1102.aspx.
    Thanks,
    Don.

  • One request, please ask your troubleshooting questions on http://forums.iis.net/1102.aspx. I am subscribed to it and it allows me to give immediate attention to your question. Someone else can also chip in and help. Plus it is useful for others too.

    Regarding MAC OS, I do not have any clue.

    Regarding some of the PHP file not working, it seems to me that they are not recognized as PHP files. Are you using 'short_open_tag'? Read http://php.net/manual/en/ini.core.php for details. If 'short_open_tag' is disallowed, you should have PHP code embeeded between . If this doesn't help, please post your question in the forum please.

    Thanks,
    Don.

  • Please post your question on http://forums.iis.net/1102.aspx. That will help you more.
    Is C:\website a physical path mapped to some web site in IIS? If not, this will not work. If it's physical path mapped to 'Default Web Site' please create a file named index.html and see if http://localhost.index.html works or not?

    Also can you put your php file in C:\inetpub\wwwroot and see if that works?

    Please post your question in the forum if this doesn't help.

    Thanks,
    Don.

  • On the forum please.

  • Thank you very much. It's very frustrating. I have been spending a couple of days trying to figure this out. No luck so far

  • Which OS you are on?

  • Hi,

    Please follow my blog at http://blogs.iis.net/donraman/archive/2009/11/15/troubleshooting-php-installation-on-windows.aspx and see if this helps.

    You can get more help at the forum, the link to which is present at http://forums.iis.net/1102.aspx.

    Thanks,
    Don.

  • Hi,

    It seems you have got a stale handler. Please delete this by invoking IIS Manger and going to Handler Mappings section.

    Thanks,
    Don.

  • Hi,
    This means that there is still mention of C:\php5\php-cgi.exe in you applicationhost.config. It is an XML file and can be found at C:\Windows\System32\inetsrv\config. You can open it and search for the string C:\php5\php-cgi.exe. Replace it with c:\Program Files\php\php-cgi.exe.
    Thanks,
    Don.

  • I came across this after I had a botched install of PHP. I uninstalled the PHP version I had and ran WPI 2.0 for PHP. I am now getting this error:
    HTTP Error 500.0 - Internal Server Error
    scriptProcessor could not be found in application configuration

  • Hi,

    Please follow my blog at http://blogs.iis.net/donraman/archive/2009/11/15/troubleshooting-php-installation-on-windows.aspx and see if this helps.

    You can get more help at the forum, the link to which is present at http://forums.iis.net/1102.aspx. Also when reporting back to the forum please paste the output of the commands I have asked in my blog. Giving more information always helps.

    Thanks,

    Don.

  • Are you running Windows? If you are runing Windows and IIS, just follow this guide. If not please search the WEB for installing PHP on MAC. I do not have any expertise on MAC.

    Thanks,
    Don.

  • Hi,

    Anonymous posts are removed periodically. So please login and try posting the comments.

    This blog is applicable to all the platforms ranging from Windows XP to Windows Vsita to Windows 7 on the client side and Windows 2003 Server to Windows 2008 to Windows 2008 R2 on the server side.

    Thanks,
    Don

Comments have been disabled for this content.