Troubleshooting PHP Installation on Windows

Posted: Nov 15, 2009  24 comments  

Average Rating

Tags
PHP
PHP Installaton

Share this Post

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.