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)
Installing PHP on IIS (Internet Information Server).
Part1 (Configuring IIS)- Run the IIS Management Console; (Control Panel->Administrative Tools and then select Internet Information Service)
- Expand the Web Sites Node, Select Default Web Site right click to get the popup menu then select Properties.
- Under Home Directory, Virtual Directory or Directory Click on the Configuration button.
- Select Mapping Tab
- Then Click Add Button
- 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 - 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 . - Save the
php.ini-dist
file asphp.ini
in the system directory(i.e \Wndows\ or \Winnt\). - Stop and restart the service
Installing PHP on PWS (Personal Web Server).
Part1 (Configuring PWS)- Run regedit
- Go to the following location:
HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/W3Svc/Parameters/ScriptMap
- Select Edit->New->String Value.
- 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
- 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 clickpws.exe
) - Go to View->Advance then append index.php, default.php, main.php in the Default Document(s) text box.
- 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 . - Save the
php.ini-dist
file asphp.ini
in the system directory(i.e \Wndows\ or \Winnt\). - Once you finished restart the computer. (because your registries need to be reloaded).
Note:
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
REGEDIT4
type your path inside[PUT PATH HERE] part.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\Script
Map] ".php"="[PUT PATH HERE]\\php.exe"
Save it and double click on it to get registered.
Installing PHP on Apache.
Part1 (Configuring Apache Server)- Locate the Apache configuration file.
It’s normally insideconf
folder of apache directory.
The name for default configuration file ishttpd.conf
- Open it and do the following.
Locate a section calledScriptAlias
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/" - 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/"
- 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” - Next Locate another section called
DirectoryIndex
Mine looks like this#
Append the following with space in between
# 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.varindex.php default.php main.php
So it’ll look some thing likeDirectoryIndex index.html index.html.var index.php default.php main.php
- Now save
httpd.conf
- Open
php.ini-dist
file in the php folder and save it asphp.ini
in any of these places, php folder itself, system directory(i.e Wndows or Winnt), directory where apache.exe located.
Testing
- Use the Notepad to Write Following
- Select File->Save
- Then Save
the file as
phpinfo.php
in following directory
For PWS/ISS :x:\Inetpub\wwwroot\
(normally it'sc:\Inetpub\wwwroot\
)
For Apache :[apache directory] \htdocs\
- Start you favorite browser and
give the following address
http://localhost/phpinfo.php
<?php phpinfo(); ?>
Make sure that you select All Files(*.*) for Save As Type.
Comments
Still unable to run php on apache?
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.