How to install PHP4 on Windows
This article is a quick guide to getting PHP 4 running on your Windows machine (be it Windows 98/Me or Windows NT/2000/XP/2003). The later versions of PHP4 allow you to install it either as an Apache module or as a CGI binary.
Published 14.11.2005 - Last edited 08.12.2005 - 23306 views - 10 comments
Installing PHP4 on Windows
Here is the step by step procedure:
1. Download the PHP binaries
PHP is free and comes complete with the source code. If you are not interested
in hacking the PHP source code, you can simply download the Windows binaries.
Both the binaries and the source code can be found at the PHP website. At the time I wrote
this, the relevant PHP binary to download comes in a zip file. The Windows
installer version does not include the binaries to run PHP as an Apache
module.
2. Installing PHP
Installation is actually trivial.
- Create a directory for PHP4 on your computer. For the purposes of this article, I will assume that you created c:\php4. Later you might want to install PHP5 to c:\php5 and you´ll have everything ready and organized.
- Extract all the files to this directory, most likely they´ll be placed in a subdir called php-4.x.x-Win32. Move all the files in this subdir to php4 and delete subdir php-4.x.x-Win32
- Move all the files from the subdirs dlls and sapi to the main dir (php4)
3. Configuring PHP
Inside the php4 directory you´ll find to files called php.ini-dist and
php.ini-recommended. Open the last one in a text-editor (Notepad) and search for
and replace (where needed) the following:
- error_reporting set to error_reporting = E_ALL & ~E_NOTICE
- register_globals set to register_globals = On if your scripts doesn´t work as intended, else leave off.
- register_argc_argv set to register_argc_argv = On if your scripts passes information in strings (index.php?var1=value1&var2=value2)
- doc_root set to the path to your Apache web directory (normally htdocs), e.g. doc_root = C:\Apache2\htdocs
- extension_dir" set to extension_dir = "C:\php4\extensions"
- SMTP set to SMTP = smtp.yourISP.com
- All done - Save your new ini file as php.ini to the main directory "c:\php4"
4. Configure Your Apache Web Server
If you want PHP to work with your Apache server, you will need to modify your
Apache configuration file to load it. Naturally, you will need to have already
installed Apache on your machine and configured it. Please read our tutorial on
how to install Apache on Windows if you haven´t already.
To configure Apache to load PHP4 as a module to parse your PHP scripts, use a
text editor to open the Apache configuration file, httpd.conf, typically found in c:\Apache2\conf.
Next, add the following lines at the bottom of this file:
# For PHP 4 do something like this: LoadModule php4_module "c:/php4/php4apache2.dll" AddType application/x-httpd-php .php .php3 .phps # configure the path to php.ini PHPIniDir "c:/php4"
To configure Apache to load PHP4 as a CGI-Binary to parse your PHP scripts add this instead:
# For PHP 4 do something like this: ScriptAlias /php/ "c:/php4/" AddType application/x-httpd-php .php .php3 .phps Action application/x-httpd-php "/php/php.exe"
Note! By using the CGI setup, your server is open to several possible attacks. Please read PHP´s CGI security section to learn how to defend yourself from those attacks.
Now all that remains is to add some variations of index files to the DirectoryIndex. Replace the DirectoryIndex line with the following:
DirectoryIndex index.htm index.html index.php index.html.var
Note! By changing the order you can make your server parse index.php before index.htm like this:
DirectoryIndex index.php index.html index.htm index.html.var
You may off course add more filetypes/extensions as well, e.g. index.phtml, index.shtml, index.php3 or whatever you use.
5. Testing Your PHP Installation
Create a PHP file with the following line: <?php echo
phpinfo() ?>
Save the file as phpinfo.php (or any other name
that you fancy, but with the ".php" extension) into your Apache htdocs
directory.
Next, restart your Apache server so that it can read the new configuration
directives you placed into httpd.conf.
Open your browser, and access the file you just created by typing http://localhost/phpinfo.php into your browser´s
location bar.
You should see an entire pageful of information about your PHP setup.
Congratulations - you have successfully installed PHP and configured Apache to
work with it. You can also use this same file, phpinfo.php, to find out more
about how your web host has set up his php.ini so that you can duplicate it on
your local machine.
1 | Thursday 13 Apr 2006 16:18:06 | Srinivas has this to say:
The exaplanation is for novice.
2 | Thursday 13 Apr 2006 16:29:53 | Thomas has this to say:
That's intentional, an expert wouldn't need a tutorial would he/she?
3 | Saturday 08 Jul 2006 12:37:00 | Alaa Kamareddine has this to say:
Dis stuff is tooo Harde
4 | Saturday 08 Jul 2006 12:43:36 | Muhammad Al Ghamdi has this to say:
Imam diyal msjied
5 | Friday 29 Sep 2006 11:18:57 | Bala Singam has this to say:
Nice work.
Thanks for the effort!
Regards!
6 | Friday 20 Oct 2006 06:24:10 | Darkserver has this to say:
looks good and i know my stuff, but yup thats a pretty good start for a noob, lol
7 | Wednesday 14 Feb 2007 21:32:09 | dimitris has this to say:
THANX FOR HELP, YOUR POST IS GREAT...
8 | Monday 06 Aug 2007 21:25:53 | Alan Hood has this to say:
Very good but I get a 403
'you are not authorised etc' error when I try to install as cgi. I have followed your instructions. Any Ideas.
I tried to install as a modile but the line
LoadModule php4_module "c:/php4/php4apache2.dll" stopped the server from starting up.
Any help would be appreciated.
9 | Tuesday 07 Aug 2007 09:54:59 | Thomas has this to say:
Alan, as PHP4 will be discontinued at the end of this year I strongly recommend upgrading to PHP5.
This might even solve your problems...
10 | Saturday 05 Apr 2008 20:44:09 | Vo Anh Khoa has this to say:
Thank you very much!
Configuring cron jobs on Windows
Up one level
PHP Sniplets