How to install PHP5 on Windows
This article is a quick guide to getting PHP 5 running on your Windows machine (be it Windows 98/Me or Windows NT/2000/XP/2003). Note! We advise you remove all files like php.ini and PHP related DLLs from the Windows SYSTEM folder before moving on with a new PHP installation.
Published 07.12.2005 - Last edited 15.08.2006 - 183932 views - 47 comments
Installing PHP5 on Windows
This tutorial is intended for installations running on Apache server 2.0.5x.
Apache versions 2.2 and greater are not supported! 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 PHP5 on your computer. For the purposes of this article, I will assume that you created c:\php5.
- Extract all the files to this directory, most likely they´ll be placed in a subdir called php-5.x.x-Win32. Move all the files in this subdir to php5 and delete subdir php-5.x.x-Win32
3. Configuring PHP
Inside the php5 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, e.g. doc_root = C:\Apache2\htdocs (normally htdocs)
- extension_dir" set to extension_dir = "C:\php5\ext"
- SMTP set to SMTP = smtp.yourISP.com
- All done - Save your new ini file as php.ini to the main directory "c:php5"
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 PHP5 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 5 do something like this: LoadModule php5_module "c:/php5/php5apache2.dll" AddType application/x-httpd-php .php .php3 .phps # configure the path to php.ini PHPIniDir "c:/php5"
To configure Apache to load PHP5 as a CGI-Binary to parse your PHP scripts add this instead:
# For PHP 5 do something like this: ScriptAlias /php/ "c:/php5/" AddType application/x-httpd-php .php .php3 .phps Action application/x-httpd-php "/php/php-cgi.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 | Monday 19 Dec 2005 18:28:44 | yamin has this to say:
Hi
i did a lot of thing in order to succesfull installation of both php5 and apache 2 but invain. now with this tutorial i am ready to use my php web base server. and plz newcomer should always use jedite editer to configure their files. thanks a lot
2 | Tuesday 20 Dec 2005 09:24:06 | Thomas has this to say:
Hi Yamin,
cool to hear that you got things up and running using this tutorial as a guide!
Happy coding :)
3 | Wednesday 21 Dec 2005 20:30:08 | mabindra has this to say:
I installed apache 2 and php 5 but when I browse for http://localhost/phpinfo.php, a file download box appears and asks whether i want to download phpinfo.php file. Help!
4 | Thursday 22 Dec 2005 09:54:09 | Thomas has this to say:
Hi Mabindra,
did you add index.php to the DirectoryIndex as shown above in Apache's config file "httpd.conf"?
5 | Thursday 22 Dec 2005 18:41:45 | mabindra has this to say:
Yeah I have done that. I reinstalled the whole thing today and tried it as it is written in this page. Now the php code as it was typed is shown on the browser instead
6 | Monday 26 Dec 2005 10:01:48 | Thomas has this to say:
If you just type in http://localhost do you get the Apache welcome message?
If you do the problem is most likely that PHP is not loaded as a module or binary. Check that all paths are correct. Below is what I use:
LoadModule php5_module "c:/php5/php5apache2.dll"
AddType application/x-httpd-php .php .phps
PHPIniDir "c:/php5"
And also make sure that:
ServerRoot "C:/Apache2"
is valid. Maybe you need to change it to:
ServerRoot "C:/Apache2/Apache2" as Apache creates Apache2 dir by default...
7 | Sunday 01 Jan 2006 10:32:10 | Eddie has this to say:
I'm looking to install php on My site but I want to test it on My PC. The problem is .PHP files will not open. I click on them and nothing happens, even after installing these engines and programs. (PHP, MySQL, and Apache)
8 | Friday 06 Jan 2006 11:17:45 | Thomas has this to say:
Even after you've installed the server software you can only execute the code through your browser, AND the php files need to be placed in the "htdocs" directory found in Apache2 directory.
Say you place a file called scripts.php in this directory, then the address in you browser should read http://localhost/scripts.php
Hope this helps!
9 | Tuesday 24 Jan 2006 21:51:58 | Brian has this to say:
I have been trying to install Apache, MySQL, and PHP5. Apache looks good, and MySQL looks good. But whenever I try to access a PHP file through local host I get this message:
The requested URL /PHP/php-cgi.exe/index.php was not found on this server.
This is the bottom of my httpd file:
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php .php3 .phps
Action application/x-httpd-php "/php/php-cgi.exe"
my php is located at c:PHP.
Help!
10 | Wednesday 25 Jan 2006 10:25:53 | Thomas has this to say:
Try loading PHP as a module, see if that helps...
LoadModule php5_module "c:/PHP/php5apache2.dll"
AddType application/x-httpd-php .php .phps
PHPIniDir "c:/PHP"
11 | Thursday 26 Jan 2006 12:41:42 | Max has this to say:
Do you store your PHP files in Apache's htdocs directory???
Try placing "index.php" in a new dir "test". The path is then:
C:\Apache2\htdocs\test\index.php
Call the page by entering this in your browser:
http://localhost/test/index.php
If you still get an error let us know...
12 | Sunday 29 Jan 2006 22:04:47 | Stuart has this to say:
I've loaded Apache, PHP5, MySQL, everything is fine but when I type in explorer : http://localhost/phpinfo.php it just gives me a blank screen. I've tried everything not one piece of php code will work. Apache works fine and MySQL and the file was loaded in htdocs.
I've been trying for a week and can't seem to get it right. Help please!
13 | Tuesday 31 Jan 2006 17:09:00 | Fritz has this to say:
Did you add php at the bottom of apache's conf file?
14 | Wednesday 01 Feb 2006 12:53:24 | Stuart has this to say:
Thanx, Yes I did. I changed php-recomended into php.ini. If you want I can mail you my php.ini and httpd.conf.
15 | Wednesday 01 Feb 2006 13:06:45 | Fritz has this to say:
Hi Stuart, send php.ini and Apache's conf file to fritz@evaria.com
I'll see if I can get it right for you...
16 | Thursday 16 Feb 2006 08:43:01 | Larry has this to say:
With the latest and gr8test version of PHP the very first instruction about upzipping is not correct but over all this is a gr8t tutorial. Thank you for the time you spent posting this. got me going just fine.Larry
17 | Tuesday 28 Feb 2006 19:20:41 | Spock's Beard has this to say:
If you find it is not working here are some tips:
1)If you're using XP Home, cut the php5ts.dll from the PHP folder and place this in C:Windowssystem32
2)Instead of using php.ini-recommended, use php.ini-dist, rename this to php.ini and continue with step 3 (you may find these are already set)
3) Use backslashes in PHP.INI and forwardslashes in the http.conf
4)If your first attempt fails following the tutorial, uinstall apache and delete php5 folder from c: Also delete the php5ts.dll from any windows directory, and make sure the apache2 folder is deleted too. So there is a fresh install.
Hope these tips help, took me a few goes to get mine installed, these are just some pointers I picked up on the way. :D
18 | Tuesday 28 Feb 2006 19:22:00 | Spock's Beard has this to say:
sorry, (1) should be C:WindowsSystem32
19 | Tuesday 28 Feb 2006 19:23:14 | Spock's Beard has this to say:
Ok this thing wont accept backslashes
C: windows system 32
20 | Tuesday 07 Mar 2006 15:27:07 | Sierra has this to say:
My last problem is that when i restart Apache after configuring httpd.conf and .ini,it says 2 times :"error parsing c:phpphp.ini on line 520".
21 | Tuesday 07 Mar 2006 15:44:06 | Roger has this to say:
Then you know where to go to correct your mistakes then...
22 | Wednesday 15 Mar 2006 14:15:35 | Lucia has this to say:
Please Help. I still can't configure PHP5. I still have the error 404 "not found" when I try:
http://localhost/phpinfo.php
I have followed all the steps over and over, don't know what else to do!
Please help me. Thanks!!!
23 | Tuesday 28 Mar 2006 22:20:34 | alek has this to say:
[WinXP,Apache2.0.55,PHP5.1.2]
I folowed steps above, and I have only html output from php scripts
help...
24 | Thursday 13 Apr 2006 07:52:17 | dtkc has this to say:
Please help. I've managed to view the PHP setup info via phpinfo.php. But I am not able to get the extensions like mysql to work. Any idea where I might have gone wrong?
Appreciate for all the help.
25 | Thursday 13 Apr 2006 11:16:33 | Thomas has this to say:
Read the article and linked material on "How to install mySQL 5.0.x on Windows" and you should be fine...
26 | Thursday 27 Apr 2006 04:51:06 | Krisitan has this to say:
Please Help. I installed Apache (2.0.55) and php5. I followed every details in changing the config files but i still get the "HTTP 404 - File Not Found" Error when testing PHP..pls help.
27 | Thursday 27 Apr 2006 13:13:00 | Thomas has this to say:
What do you get when you try to open http://localhost ?
The 404 error is basically just a message that the server cannot find the file in the spesified directory, NOT that PHP isn't running...
28 | Friday 28 Apr 2006 11:54:25 | Kristian has this to say:
I switched to Apache (2.0.52) and PHP (4.3.9).
The Apache installation was ok. But the PHP script won't display as supposed to. Setting the browser to "http://localhost/phpinfo.php", only displays the script itself "". Please help.
29 | Friday 28 Apr 2006 12:05:23 | Thomas has this to say:
Sounds to me like Apache isn't communicating with php. You can test this by setting an invalid path to your extension dir...
extension_dir = "nowhere"
in php.ini
Restart Apache and if it reads php.ini you should get a error message...
30 | Friday 28 Apr 2006 12:28:59 | Thomas has this to say:
The above didn't work as intended...
At the bottom of Apache's config file I have the following (php5)
LoadModule php5_module "c:/php5/php5apache2.dll"
AddType application/x-httpd-php .php .phps .asp
PHPIniDir "c:/php5"
for php4 it should read
LoadModule php4_module "c:/php4/php4apache2.dll"
AddType application/x-httpd-php .php .phps
PHPIniDir "c:/php4"
Try changing the name of the dll file and then restart Apache.
The best however is to competely remove Apache, mySQl and php and make a fresh install. This includes directories and windows services...
31 | Friday 05 May 2006 19:13:43 | Hwa has this to say:
Problem starting Apache2.2 service with PHP 5.1.13 on Windows XP Professional after installing Apache2 & PHP...
Got the error:
Windows could not start the Apache 2.2 on local computer. For more information, review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific errorcode 1.
If I remove: LoadModule php5_module "C:/PHP/php5apache2.dll"
Apache service starts & the web server works fine.
Any hints on what I am doing wrong would be greatly appreciated!
32 | Tuesday 09 May 2006 12:03:03 | SkyBlueshoes has this to say:
I get the same error trying to load the php5 module with Apache2.2. However, if I load the cgi binary, Apache starts fine, but I am unable to access the phpinfo.php file. I get a 403 error.
33 | Tuesday 09 May 2006 12:34:15 | Thomas has this to say:
When compiling php 5.1.2 on Debian with Apache 2.2.0, I ran into problems with libxml2 and libxml2-config not found errors. After checking the base install, Debian leaves out the libxml2 headers, they can be downloaded using apt-get:
apt-get install libxml2 libxml2-dev
PHP should then compile fine.
On a Windows system you should NOT be using Apache version 2.2 as PHP is still meant to run on Apache 2.0.xx
34 | Friday 19 May 2006 17:58:32 | Thomas has this to say:
No adds in this section please!
35 | Thursday 25 May 2006 08:35:02 | Cs has this to say:
It's clear from this discussion that a lot of people have trouble getting php to work. And Thomas provides zero information to help them along. If the user wants to use a cgi-binary, don't tell them to load a module.
When I install phpinfo.php in htdocs/ and access it via localhost/phpinfo.php, I get a 403 error: permission denied. Presumably this means that something somewhere in httpd.conf need to be modified to allow the script to be interpreted. If I move the script into my cgi-bin directory and access it via either localhost/phpinfo.php or localhost/cgi-bin/phpinfo.php, I get a file not found error. Which presumably means that httpd.conf needs to be modified to tell apache that it can look in cgi-bin to run scripts.
So does that provide sufficient insight into the minds of people who are trying to get PHP to run to help you explain what configuration parameters need to be set that aren't being documented?
36 | Thursday 25 May 2006 12:12:22 | Thomas has this to say:
In order to get php5 up and running as explained in this tutorial you need to install Apache 2.0.5x and php5 EXACTLY as I did (and to the same location!) in my tutorial found on this site. Otherwise you need to change the paths where applicable.
The 404 errors typically occurrs when you have a misleading path somewhere.
I also get a lot of frustrated emails requiering that I fix their problems. I posted this tutorial to help people on their way, I didn't create either of the software packages. So if you're unable to get it going yourself please report your bugs or problems to one of their websites. (The links are found in my link section...)
37 | Tuesday 30 May 2006 10:24:22 | Thomas has this to say:
In reply to Cs
I didn't tell people to install php as a module, I gave them a choice between that and a cgi-binary.
Please read the article before you make a fool of yourself.
38 | Friday 02 Jun 2006 06:39:21 | Amit has this to say:
Hello friends, Please help me !
I have problem with php5.
I am trying to run php5 on my computer system. My current operating system is Windows98. Also I am useing PWS server I have downloaded the php5 in ".zip" format from "www.php.net" and extract it to location "c:php". After that I have downloaded the installer for php5 from www.php.net . This installer runs successfuly After that i have made on sample file as test.php contining code as follows
& save this file to location c:wwwrootinitpub est.php
(as im uses PWS).
Also note that i have "set all permission like Read, Write, Exicute".
After that i tried to run my first php script i.e. "test.php". && here i faced problem. Whenever i try to run my browesr try to download test.php. I dont know whats going on. So is any buddy thier who can HELP me. Plase reply or mail me at "555.amit@gmail.com". If any one helpme then im very greatefull.
Thanks
Regards
Amit
39 | Friday 02 Jun 2006 12:16:55 | Thomas has this to say:
It's been 6 years since I left Win98 (didn't know anyone used it anymore...).
I believe your problems are related to PWS as you probably need to change some paths etc. in order for it to recognize your updated PHP installation.
Further it might be that PWS doesn't support PHP5 as IIS replaced it's development back in 2000...
If I were you I'ld consider an upgrade of the OS (or change to another) in order to avoid any future problems.
40 | Sunday 04 Jun 2006 21:19:27 | Sana has this to say:
Hi I am trying to setup PHP 5 and Apache 2.2 on Windows XP as a testing server. I've tried several configurations but in vain.
I've installed php 5 to
C:/PHP
and Apache 2.2 to
C:Program FilesApache Software FoundationApache2.2
Everything seems to work fine with .html pages but I ain't able to see .php pages. Whenever I try to open phpinfo.php, it shows me the following erorr
You don't have permission to access /php/php-cgi.exe/phpinfo.php on this server.
I don't know what's wrong. Please help
41 | Monday 05 Jun 2006 12:19:21 | thomas has this to say:
Sana see comment #33. Uninstall and remove all dirs and files and then follow our tutorials and set up PHP5 with Apache 2.0.58 instead of 2.2...
42 | Tuesday 06 Jun 2006 09:34:57 | gil has this to say:
this tutorial is just great
43 | Tuesday 06 Jun 2006 14:26:16 | OlegBou has this to say:
#33,40-41! http://snaps.php.net/
with 5.2release: the ZIP contains php5apache2_2.dll
usage this library instead of php5apache2.dll solves
LoadModule problem!
44 | Wednesday 07 Jun 2006 21:22:18 | Asaf has this to say:
Hi, brillinat tutorial. I uninstalled apache 2.2.2 and installed the 2.0.2 and the PHP works ALMOST fine. strangely it shows the right result for http://localhost/index.php but when I put only http://localhost/ in the address line I get the source code in the browser window. What can be the reason? How can I fix it?
45 | Thursday 08 Jun 2006 09:38:33 | Thomas has this to say:
Did you change the "DirectoryIndex" in the Apache's config file to include index.php as follows:
DirectoryIndex index.php index.html index.htm index.html.var
46 | Friday 09 Jun 2006 19:29:40 | Endru has this to say:
I used Opera and it said that
Forbidden
You don't have permission to access /php/php-cgi.exe/hello.php on this server.
Anyone know why is that so? Help me please...
47 | Monday 19 Jun 2006 17:45:11 | Admin has this to say:
Due to SPAM we're closing the comments on this article.
Configuring cron jobs on Windows
Up one level
PHP Sniplets