Installing PHP as CGI binary (on Windows Platform)

This is a set of Instruction rather than a tutorial, for those who want to get the PHP up and running as soon as possible. I'll be looking forward to discuss more PHP with you in the future. So this could be a good starting point.

Installing PHP as CGI Binary(on Windows Platform)

  1. Installing PHP on IIS.
  2. Installing PHP on PWS.
  3. Installing PHP on Apache.

Installing PHP on IIS (Internet Information Server).

Part1 (Configuring IIS)
  1. Run the IIS Management Console; (Control Panel->Administrative Tools and then select Internet Information Service)
  2. Expand the Web Sites Node, Select Default Web Site right click to get the popup menu then select Properties.
  3. Under Home Directory, Virtual Directory or Directory Click on the Configuration button.
  4. Select Mapping Tab
  5. Then Click Add Button
  6. Under Executable, give the path where your php.exe is located e.g x:\php\php.exe
    Under Extension, give .php
    Leave the rest as it is, that is All Verbs Selected and Script Engine checked
  7. Open php.ini-dist file in the php folder and find ; cgi.force_redirect = 1, take off the semicolon (comment) then turn off cgi.force_redirect by making the value equal to zero .
  8. Save the php.ini-dist file as php.ini in the system directory(i.e \Wndows\ or \Winnt\).
  9. Stop and restart the service

Part2 (Testing)

Installing PHP on PWS (Personal Web Server).

Part1 (Configuring PWS)
  1. Run regedit
  2. Go to the following location:
  3. Select Edit->New->String Value.
  4. The Rename the 'New Value #1' under the name column as .php and double click on that to enter data for the value. Then type the path of your php.exe for example my path is H:\php\php.exe
  5. Run the Personal Web Manager (Usually it is located on you desktop as Publish, if you don't find it go to your WINDOWS\SYSTEM\inetsrv\ directory and double click pws.exe)
  6. Go to View->Advance then append index.php, default.php, main.php in the Default Document(s) text box.
  7. Open php.ini-dist file in the php folder and find ; cgi.force_redirect = 1, take off the semicolon (comment) then turn off cgi.force_redirect by making the value equal to zero .
  8. Save the php.ini-dist file as php.ini in the system directory(i.e \Wndows\ or \Winnt\).
  9. Once you finished restart the computer. (because your registries need to be reloaded).

If you are not sure about the registry editing you can locate the pws-php4cgi.reg file usually in \php\SAPI\ directory right click on that and Edit usually it looks like this
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script Map] ".php"="[PUT PATH HERE]\\php.exe"
type your path inside[PUT PATH HERE] part.
Save it and double click on it to get registered.

Part2 (Testing)

Installing PHP on Apache.

Part1 (Configuring Apache Server)
  1. Locate the Apache configuration file.
    It’s normally inside conf folder of apache directory.
    The name for default configuration file is httpd.conf
  2. Open it and do the following.
    Locate a section called ScriptAlias
    Mine looks like this
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the realname directory are treated as applications and
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    ScriptAlias /cgi-bin/ "H:/apache2/Apache2/cgi-bin/"
  3. Add the following
    ScriptAlias /php/ “[path where your php folder is located]”
    My ScriptAlias looks like this
    ScriptAlias /cgi-bin/ "H:/apache2/Apache2/cgi-bin/"
    ScriptAlias /php/ "H:/php/"
  4. Now add the following in the end
    AddType Application/x-httpd-php .php
    Action Application/x-httpd-php "[path where php.exe is located, by the way you can ignore the drive info i.e c:/ if both apache and php are in the same drive]”

    Mine looks like this. I tend to add comments because it'll be easy to tack down errors.
    #Author: Janaka Wickremaisnghe
    #Purpose: PHP Configuration
    #Created: 30-March-2004
    AddType Application/x-httpd-php .php
    Action Application/x-httpd-php “/php/php.exe”
  5. Next Locate another section called DirectoryIndex
    Mine looks like this
    # DirectoryIndex: sets the file that Apache will serve if a directory
    # is requested.
    # The index.html.var file (a type-map) is used to deliver content-
    # negotiated documents. The MultiViews Option can be used for the
    # same purpose, but it is much slower.
    DirectoryIndex index.html index.html.var
    Append the following with space in between
    index.php default.php main.php
    So it’ll look some thing like
    DirectoryIndex index.html index.html.var index.php default.php main.php
  6. Now save httpd.conf
  7. Open php.ini-dist file in the php folder and save it as php.ini in any of these places, php folder itself, system directory(i.e Wndows or Winnt), directory where apache.exe located.

Part2 (Testing)


  1. Use the Notepad to Write Following

  2. <?php phpinfo(); ?>
  3. Select File->Save

  4. Make sure that you select All Files(*.*) for Save As Type.
  5. Then Save the file as
    phpinfo.php in following directory
    For PWS/ISS : x:\Inetpub\wwwroot\ (normally it's c:\Inetpub\wwwroot\)
    For Apache : [apache directory] \htdocs\
  6. Start you favorite browser and give the following address


Still unable to run php on apache?

July 8, 2004 by Janaka Wickremasinghe

If you still having difficulties such as 404-Unable to find file or 400-Bad request, try copying php.exe and php4ts.dll to the apache folder where apache.exe located.

You must me logged in to write a comment.