Troubleshooting PHP Installation on Windows

Posted: Nov 15, 2009  5 comments  

Average Rating

Tags
PHP
PHP Installaton

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.

Comments

  1. don.raman
    November 19, 2009

    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 www.iis.net/.../fastcgi. On Vista+ OS, FastCGI is built withing OS. Just read this section learn.iis.net/.../using-fastcgi-to-host-php-applications-on-iis-70.

    Hope this helps.

    Thanks,

    Don.

  2. don.raman
    November 24, 2009

    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' <no quotes please>

    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 support.microsoft.com.

    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.

  3. don.raman
    November 30, 2009

    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.

  4. don.raman
    December 9, 2009

    Hi Jaya,

    Sorry to hear about that. Since you are running Wndows 2003, you can configure FastCGI manually by following the article at learn.iis.net/.../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 forums.iis.net/1102.aspx.

    Hope this helps.

    Thanks,

    Don.

  5. don.raman
    December 18, 2009

    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.

Submit a Comment