Troubleshooting PHP Installation on Windows

My PHP installation is not working? I am not able to run my PHP scripts? A simple PHPINFO page is not loading in my browser? These are typical questions I hear from users in the forum. I would still say the best way to install PHP is to use WPI as described by me here and here. I am telling this because WPI installation involves non-manual steps of installing PHP 5.2.11 or PHP5.3.

However software like manually installing things are not 100% safe and are bound to fail. I am going to explain how to troubleshoot your PHP installation. The first suggestion is to use WPI to install it. Following this troubleshooting will be simple if you have followed my way of installing PHP. And yes, this troubleshooting is for PHP configured to run with IIS FastCGI and Non Thread Safe version of PHP. This troubleshooting is not for PHP running with IIS in ISAPI mode. We recommend that PHP on IIS should use IIS FastCGI with Non Thread Safe version of PHP if you are running XP or later Operating System.

I would like to tell you to do certain things to figure out the problem in PHP installation. It would be good if you can tell results of below commands/observations while reporting problem to forum.

If you are on XP/2k3

Run the below command and see if output is similar to what is here (I am assuming your system drive is C:).

cscript.exe C:\inetpub\AdminScripts\adsutil.vbs GET w3svc/DefaultDoc

cscript.exe C:\inetpub\AdminScripts\adsutil.vbs GET w3svc/ScriptMaps | findstr php

This is the output you should get from first command:

DefaultDoc    : <STRING> "Default.htm, Default.asp, index.htm, index.php"

This is from the second cssript command:

".php,C:\WINDOWS\system32\inetsrv\fcgiext.dll,5,GET,HEAD,POST"

If you are getting empty or something else you should doubt your installation.

Look at directory 'C:\WINDOWS\system32\inetsrv' (I am assuming that C: is your system drive) and ensure that you have:

  • fcgiext.dll
  • fcgiext.ini
  • fcgiconfig.js

Also open the fcgiext.ini file and see if things are proper. A properly set INI file should ideally have:

[Types]
php=PHP

[PHP]
ExePath=C:\Program Files\PHP\php-cgi.exe
InstanceMaxRequests=10000
ActivityTimeout=600
RequestTimeout=600
EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000,PHPRC:C:\Program Files\PHP\

Ensure that C:\Program Files\PHP\php-cgi.exe exists. and there is a valid php.ini file in the same directory.

If you are on Vista/2k8/WIN7/R2

Run the below command:

%WINDIR%\system32\inetsrv\appcmd.exe list config /section:fastcgi /text:*

%WINDIR%\system32\inetsrv\appcmd.exe list config /section:handlers /text:* | findstr /i PHP

The output of first command should be something like:

CONFIG
  CONFIG.SECTION:"system.webServer/fastCgi"
  path:"MACHINE/WEBROOT/APPHOST"
  overrideMode:"Inherit"
  locked:"false"
  [system.webServer/fastCgi]
    [application]
      fullPath:"C:\Program Files\PHP\php-cgi.exe"
      arguments:""
      monitorChangesTo:""
      stderrMode:"ReturnStdErrIn500"
      maxInstances:"4"
      idleTimeout:"300"
      activityTimeout:"600"
      requestTimeout:"600"
      instanceMaxRequests:"10000"
      signalBeforeTerminateSeconds:"0"
      protocol:"NamedPipe"
      queueLength:"1000"
      flushNamedPipe:"false"
      rapidFailsPerMinute:"10"
      [environmentVariables]
        [environmentVariable]
          name:"PHP_FCGI_MAX_REQUESTS"
          value:"10000"
        [environmentVariable]
          name:"PHPRC"
          value:"C:\Program Files\PHP\"

The output of second command should be something similar to:

name:"PHP_via_FastCGI"
path:"*.php"
scriptProcessor:"C:\Program Files\PHP\php-cgi.exe"

If the output is NIL (I mean nothing) or drastically different please double check your installation. By drastically different I mean something missing. Please don't pay too much attention on their values.

Applies to all the platforms

All the executables/DLL available marked in color red above should be present at their respective location. You should also have a valid PHP.INI file at the location marked in blue above.

Ensuring that php-cgi.exe is working properly

There are so many reasons you can get 500 if php-cgi.exe is not working properly. Some of them can be:

  • Some PHP extension creating problem and not loading properly
  • Programming error

Programming error is something which you will need to take care. I would tell you to use a simple PHP file containing below lines ton test your PHP executable:

<?php
echo 'This is my first PHP program';
?>

Please name the above file as 'test.php' in your webroot folder (PHP SERVER variable _SERVER["DOCUMENT_ROOT]") and save it. I will be using 'C:\inetpub\wwwroot' as this is my webroot folder and also the place where my PHP_SERVER variable _SERVER["DOCUMENT_ROOT"] is set.

You can check that your PHP is running fine by running below two commands:

"C:\Program Files\PHP\php-cgi.exe" -v

"C:\Program Files\PHP\php-cgi.exe" C:\inetpub\wwwroot\test.php

The first command should print something like:

C:\Windows\system32>"C:\Program Files\PHP\php-cgi.exe" -v
PHP 5.3.1RC4 (cgi-fcgi) (built: Nov 12 2009 22:32:27)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

without any error or pop-up dialog. If there is a dialog complaining about missing library please pay attention to it. It might make your PHP not running well in the browser. This result should come clean. I mean without any pop-up dialog. If you are getting some dialog about missing library either get that library or disable the extension responsible for it in your PHP.INI file. in order to disable the extension, do the following:

  • Figure out all the lines in PHP.INI file starting with 'extension='
  • Comment one at a time and run the above command
  • Figure out which extension is creating problem and comment it out by appending a ';' in the beginning

The second command should print 'This is my first PHP program' on the command line, something like:

X-Powered-By: PHP/5.3.1RC4
Content-type: text/html

This is my first PHP program

PHP outputting the file itself

Please read my blog here for a solution.

localhost/IP address of your machine is resolving properly

Make sure that a plain HTML file in your webroot can be accessed by http://localhost/default.html

If not there is a DNS problem, try resolving it with your internet service provider.

IIS Default Web Site/localhost is configured properly

Please make sure that:

One can also use the command line utilities to find information about site binding port and physical path:

On Vista/2008/Win7/R2

%WINDIR%\system32\inetsrv\appcmd.exe list site

SITE "Default Web Site" (id:1,bindings:http/*:80:,state:Started)
SITE "My Web Site" (id:2,bindings:http/*:81:,state:Started)

%WINDIR%\system32\inetsrv\appcmd.exe list vdirs

VDIR "Default Web Site/" (physicalPath:C:\inetpub\wwwroot)
VDIR "My Web Site/" (physicalPath:C:\inetpub\mywebsitewwwroot)

On XP/2k3

Run 'inetmgr'

Select 'Default Web Site' and click on 'Properties

In the 'Web Site' Tab you will find TCP Port which is the binding port

In the 'Home Directory' Tab you will find the physical path as named 'Local Path'

These are important because if your binding port is different, let's say 81 you will need to give http://localhost:81 in your browser rather than just http://localhost. This is because the browser address  http://localhost means it is bounded to default port 80 in case of IIS. Ensure that the port used by 'Default Web Site' is not occupied by any other program like Skype.

'Physical Path' is the folder where you should keep your 'test.php' file. Now try accessing 'test.php' in browser and see what happens. If you are not able to run 'test.php' properly, please disable browser's friendly HTTP error display and run 'test.php' again. In Internet Explorer, friendly HTTP errors display can be turned off by going to Tools-->Internet Options-->Advanced and uncheck 'Show friendly HTTP errors' under 'Browsing' section. This will show you the IIS detailed error page.

Other reasons for failure

  • IIS also has this concept of inheriting the settings from parent. But in some cases an application under site can have it's own handler mapping etc. Please ensure that if this is the case you are checking the handler mapping not against the site but the application in question. You don't need to turn your folder into an application to run PHP but I have seen few people doing it. This was the mistake which was found at http://forums.iis.net/t/1162291.aspx. Please avoid this. Again you just need to create a folder inside your web root. Please do not try turning that folder into an application and overwriting the handler mappings or any other setting if not desired.

What I would do to test the PHP installation is to create a new folder and put the test PHP file into that folder and test it from the browser. It is safe and avoids any confusion like the one above.

  • PHP MSI internally runs some of the FastCGI script to write some values to the FastCGI INI file and create handler mapping depending on OS you are running. At least once I found that it was not behaving correctly. In that case try creating the handler mapping manually. For details look at the forum at http://forums.iis.net/t/1162874.aspx. This was resulting into a 404 error.

Now you know some basic steps to troubleshoot your PHP installation. I will keep this blog updated as and when I know more reasons. But till then, thanks for the patient reading and GOOD BYE.

Don.

24 Comments

  • Hi,

    Yes, you can directly run the MSI. PHP 5.2.x base is not must. However if you are running the MSI directly please ensure that prior to running that you have FastCGI instaled on IIS. I am not sure which OS you are on. You don't need to configure FastCGI, just ensure that it is instaled. For XP/2k3 it means just installing FastCGI from http://www.iis.net/expand/fastcgi. On Vista+ OS, FastCGI is built withing OS. Just read this section http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/#EnableFastCGI.

    Hope this helps.

    Thanks,
    Don.

  • Hi Dinesh,

    If you have done all the things correctly PHP should have been working. This might be because some bug in PHP MSI. Since the output of command "cscript.exe C:\inetpub\AdminScripts\adsutil.vbs GET w3svc/ScriptMaps | findstr php" is blank and you are on Windows XP SP2, please configure the handler mapping manually and see if PHP works. Please follow the below steps:

    1. Click Windows + R button (or go to Start menu and click on Run button)
    2. Type 'inetmgr' and press 'OK' button
    3. Expand the tree on left hand side. You can see your machine name with a '+' button. Click on it.
    4. Click on 'Web Sites' and select 'Default Web Site'.
    5. Right click on 'Default Web Site' and click on 'Properties'
    6. This will open up the site's property dialog box. Click on 'Home Directory' tab.
    7. On this page click on 'Configuration' button. THe 'Configurtion' button is grouped under 'Application Settings'
    8. Click on 'Add'
    9. Click on browse button and browse to folder 'C:\Windows\System32\inetsrv'
    Note: If you need to use FastCGI in 32 bit mode on a 64 bit machine, then browse to %WINDIR%\SysWOW64\inetsrv.
    10. Select 'fcgiext.dll' and click 'OK'
    11. In the 'Extension' field type '.php'
    12. In the 'Verbs' section select 'Limit to' and type GET,HEAD,POST in the text box
    13. Click on 'OK' button.

    If the 'OK' button is grayed out please follow the KB article at http://support.microsoft.com/?id=317948.

    Restart IIS (not required but to be sure) by typing 'iisreset' on a command prompt.

    You are all set now to run PHP in your browser.

    Thanks,
    Don.

  • Hi Dinesh,

    The IIS component responsible for running PHP is called FastCGI. The code base of this component is same for IIS5.1 and IIS7.0. So that should not be the problem. However I cannot guarantee this. My hunch is that maybe PHP itself is creating the problem. You will need to do little bit of debugging at your end to isolate the problem. See if the application works well with older version of PHP (PHP5.2.11) or not. Also see what kind of hang you are getting. Is it resulting into some kind of activity timeout? Is the application not able to connect to database? Put some debug statements in the application and try to find out what PHP code is responsible for the hang.

    So my advise will be to do some more debugging and find out the reason for this. Once you have the reason for hang, it will be easier fixing it.

    Thanks,
    Don.

  • Hi Jaya,

    Sorry to hear about that. Since you are running Wndows 2003, you can configure FastCGI manually by following the article at http://learn.iis.net/page.aspx/247/using-fastcgi-to-host-php-applications-on-iis-60/. If you have further problem, please feel free to ask for help in the forum at http://forums.iis.net/1102.aspx.

    Hope this helps.

    Thanks,
    Don.

  • Hi All,

    For some reason comments are getting deleted from the post and I do not have any clue. So please be patient until I figure out this mystery. And thanks for all the lovely comments and suggestion.

    Thanks,
    Don.

  • Don,

    That's one hell of a list of checks which I have had to adjust a little because I am using 64bit Windows 7 and IIS 7.5. Everything involving PHP, IIS and FastCGI including Handler Mappings looks correct and I have absolutely no problem with PHP websites not involving a MySQL database. I originally installed PHP version 5.3.1 which gave HTTP Error 500 with a simple script including:
    $connection= mysql_connect("localhost", "root", "password");
    I had earlier tried the mysqlI version with same result. Both of these MySQL extensions are present in the ...PHP\ext folder.
    Uninstalling PHP 5.3.1 and installing 5.2.12 made no difference.

    Perhaps this is a MySQL problem? Last year I worked through various Windows 7 releases each time reinstalling programs like MySQL until I changed to 64 bit Windows 7 with the production release. At this point I installed MySQL 5.0 and ODBC Connector 5.1, both of which I believe are 64 bit versions. I see however that I have an old 3.51 connector lying around which might confuse something. On the other hand, MySQL databases are accessible through the Command line and Microsoft Office 2007 ACCESS, using "localhost" and "root" as above.

    If you have any suggestions I should be grateful. In the meantime I shall look at the MySQL installation and prhaps re-install.

    Keep up the good work and thanks for your previous posts.

  • Hij
    I am afraid I am one of those annoying novices!
    I have down loaded the WPI launcher and wordress so that I can run wordpress from my laptop. all the boxes say that everything is loaded but when I go to http://localhost/ wordpress and click the load wordpress I get a box which says --application/x-php from http://localhost--I then click the button open and it downloads this-- iZw2odsf.part-- which I can do nothing with!!!!
    the forum guy don sent me your link as he thinks the php may be corrupted.

    From your trouble shooting blog I have found out that I am missing the files fcgiext.ini and fciconfog.js
    what is the best thing to do?

    please reply in the simplest most childish language you can think of...as Sir Randolf Finnes said when asked how did he manage to climb Mount Everest he replied" one step at a time"!! well this is my Everest
    many thanks
    Huw

  • Hi Jaygeeuk,

    Thank you for the post. Please look at http://bugs.php.net/bug.php?id=50172 for resolution on this. This should solve your problem.

    Thanks,
    Don.

  • Hi Huwgriff,

    Can you please let me know which OS you are running? Also let's continue the discussion in the forum. The resolution will helpd others too and if you are on the forum, other people might be able to help you.

    Thanks,
    Don.

  • Which product did you download? And what is the error you are getting running a simple PHP page.

    Thanks,
    Don.

  • When I go to http://www.websitename/phpinfo.php I am getting a proper PHPINFO page where you are running PHP 5.2.4. Please upgrade to PHP 5.2.13 as this has lot of bug fixes and important security updates. Just an advice form my side. And post your queries in PHP forum where you will get faster reply.

    Thanks,
    Don.

  • thanks! this guide was very helpful & solved my problem.

  • Don,

    WPI is a life saver. Installed one 2008R2 webserver and it took about 30 days, not fault of programs but my ignorance to get php properly installed. I then found WPI and it got another server running in 8 hours from start to finish and I have now moved all websites to it.

    Question I have is we are looking at loading Concrete5, a php-CMS program on this new webserver. Have you had any experience or known issures with Concrete5?

    Thanks for your great knowledge.

    Terry

  • Hi Terry,

    No I do not have any expereince with Concrete5 but seems like it is supported on Windows. Give it a try and let me know in case you are facing any problem.

    Thanks,
    Don.

  • Anonymous comments are removed periodically, so please login and comment. Also try asking question in the forum. You will get help quickly. The link to the forum is http://forums.iis.net/1102.aspx. Another thing IIS FastCGI is built within Windows 2008 R2. And those files are meant to exist on XP/Windows 2003. Please read instructions carefully.

    Thanks,
    Don.

  • thanks... this help me

  • This is very very useful, thanks

  • Very veruy useful, thanks

  • I am having an issue running this simple script to a local MS SQL server:

    <?php
    // Server in the this format: \ or
    // , when using a non default port number
    $server = 'KALLESPC\SQLEXPRESS';

    // Connect to MSSQL
    $link = mssql_connect($server, 'sa', 'phpfi');

    if (!$link) {
    die('Something went wrong while connecting to MSSQL');
    }
    ?>
    echo 'Connection to MSSQL Has been established
    '; //for testing
    ?>

    running:


    have no issue.

    And if I point the script to a MySQL server it's also fine. Can you help?

  • First of all MSSQL PHP extension has been deprecated from PHP5.3.2 and should not be used. It depends some of the old Microsoft libraries which are no longer supported. Also if you are using PHP5.2 sometime the extension doesn't load because of missing ntwdb.dll or MSVCR71.dll. Check your phpinfo() page to ensure that the extension is loaded.

    A more elegant and recommended solution is to switch to new SQLSRV driver to connect to MS SQL Server. Details at http://blogs.iis.net/donraman/archive/2010/01/25/working-with-microsoft-sql-server-driver-php-sqlsrv-dll-for-php-on-windows.aspx. An example of connecting to MS SQL Server using new SQLSRV PHP driver can be found at http://msdn.microsoft.com/en-us/library/cc296161(SQL.90).aspx.

    SQL team has also got the forum where you can ask question. Details about that in my blog link above.

    Hope this helps.

  • Please also follow http://msdn.microsoft.com/en-us/library/cc793139(SQL.90).aspx for further details about usage of SQLSRV PHP API.

  • I did all the instructions and everything works right but still a simple PHPINFO page is not loading in my browser, in chrome and firefox it download the 'test.php' file...

  • This means either the script/handler mapping for .php file is not corect (which you are saying is not the case) or you are running into http://blogs.iis.net/donraman/archive/2009/11/01/running-php-displays-the-code-itself.aspx.

    Please use the IIS PHP forum at http://forums.iis.net/1102.aspx as there are may people willing to help and response will be faster.

    Thanks,
    Don.

  • Well no anonymous comments are getting approved. So please login and comment.

    Sorry for the inconvenience.

    Don.

Comments have been disabled for this content.