Click to See Complete Forum and Search --> : PHP 5 under Windows


bpat1434
06-17-2007, 11:00 PM
Apache 2 with PHP 5
This guide is for any user that is running Windows (any version) and wants to run the Apache Web Server (http://httpd.apache.org) with php5.


Download Required Files

Apache
Go to Apache Download Section (http://httpd.apache.org/download.cgi) and download Apache. I'm using Apache version 2.2.8 for this tutorial.
PHP Files
Go to PHP.net (http://www.php.net) and download the Windows zip package 5.2.x (or whatever the current release is). Do NOT download the executable files.

Install Apache

Run the Apache Install program [Image (http://phpbuilder.bpatterson.net/WAMP_Install/apache_1.png)]
Input "localhost" for the network domain, "localhost" for the servername, and "root@localhost", or any email address you want, for the administrator's email address. Also keep the default selection of running apache for all users on port 80. [Image (http://phpbuilder.bpatterson.net/WAMP_Install/apache_2.png)]
Choose a "Custom Install" option [Image (http://phpbuilder.bpatterson.net/WAMP_Install/apache_3.png)]
Customize the settings as you feel fit. Most of them can be left as default though.
Install the Apache Webserver on your system
Make sure Apache is Running. You should see the feather logo in the system tray if you are running the ApacheMonitor program (which is the default) [Image (http://phpbuilder.bpatterson.net/WAMP_Install/apache_4.png)]

Set Up PHP

Unzip the PHP files to a directory [Image (http://phpbuilder.bpatterson.net/WAMP_Install/php5_1.png)]
Rename php.ini-recommended to php.ini
Edit php.ini file as needed
Run through the php.ini file and change any items you want. I use the error level E_ALL & E_STRICT in php5. You can change them to what you want. I also load a bunch of modules. There is no "master" setting, so fiddle with it until you get what you need / want.

NOTE: You should set a default timezone in your php.ini file. For a listing of default timezones, please refer to the PHP manual's Timezones Page (http://us.php.net/manual/en/timezones.php)
Copy php5 folder to its permanent spot [Image (http://phpbuilder.bpatterson.net/WAMP_Install/php_1.png)]
You can put this anywhere you please. Most people tend to put it at the root of C: "C:\php". You can put it wherever you like. Since PHP is a program, I'm going to stick it in "C:\Program Files (x86)".

NOTE: I have an x86_64 system so I have both C:\Program Files and C:\Program Files (x86). There is no special difference between the directories in this case.

Create httpd-php.conf file

Create a new file in <Apache Root>/conf/extra/ called "httpd-php.conf"
Inside the new file, put either block for running PHP as a CGI or running it as a Module:

# PHP 5 as CGI
<Directory "C:/your/path/to/php5/">
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
ScriptAlias /php5/ "C:/Program Files (x86)/Web Server/php5/"
AddHandler application/x-httpd-php5 .php5
Action application/x-httpd-php5 "/php5/php-cgi.exe"


#
# PHP 5 as Module
LoadModule php5_module "C:/Program Files (x86)/Web Server/php5/php5apache2_2.dll"

<IfModule php5_module>
AddType application/x-httpd-php .php .php3 .php5
AddType application/x-httpd-php-source .phps
PHPIniDir "C:/Program Files (x86)/Web Server/php5"
</IfModule>

Edit the spots in red to reflect the proper path to php5
NOTE: If you're running Apache 2.0.x, then use php5_apache2.dll. If you're running Apache 2.2.x, then use php5_apache2_2.dll
Save the file
Edit httpd.conf and add this line (includes previously created file):
Include conf/extra/httpd-php.conf

Add PHP to path of Windows

Right click on "My Computer" and select "Properties" [Image (http://phpbuilder.bpatterson.net/WAMP_Install/php_2.png)]
Vista Users:
Click on the link in the left that says "Advanced System Settings" [Image (http://phpbuilder.bpatterson.net/WAMP_Install/php_3.png)]
Open the "Advanced" tab in the System Properties box
Click on the button which says "Environment Variables..." in the lower right hand corner [Image (http://phpbuilder.bpatterson.net/WAMP_Install/php_4.png)]
Edit the "Path" variable in the "System Variables" section [Image (http://phpbuilder.bpatterson.net/WAMP_Install/php_5.png)]
You need to add the paths to your PHP folder separated by a semi-colon ";". For example, my addition looked like:
;C:\Program Files (x86)\Web Server\php5

Restart the Computer
It's best to restart the computer because windows needs to update it's Path variable since we edited it. It's optional, but until you do, some extensions may not load properly.


That's it. By this time you should have a working copy of php5 on your system for testing. To test this, you can simply create a new document called info.php and in it put the following contents:
<?php phpinfo(); ?>
Now save this file to the DocumentRoot which you defined in your httpd.conf file above (by default it's "<Apache Root>/htdocs") and then browse to http://localhost/info.php and you should see a slew of information about PHP and your system spit out at you


[ NOTE ] [i]I removed the part about php4 concurrency because php4 is reaching EOL (End of Life) and as such, you should not be running it. You should be running php5 from now on. If you still need help running php4 concurrently, feel free to ask me; however, I won't support php4 past it's life.

InProgress
07-26-2007, 08:43 AM
Hi bpat1434,

I'm going to install Windows Vista Home Premium 64 on my computer.

But, I'm affraid that program like Apache and PHP will not work correctly.

In the other reply for 'installing php on vista 64', you wrote "...and Vista Ultimate 64 is my OS...".

Does it mean that this tutorial also compatible for all Windows Vista 64 edition?

bpat1434
07-26-2007, 08:50 AM
Yes. Apache and PHP will run on any Vista release.

InProgress
07-26-2007, 09:08 AM
Thanks bpat, thats great!

Did you also write tutorial for installing mysql and ssl for Apache 2.2?

I'd like to read them as well.

bpat1434
07-26-2007, 09:35 AM
Go to Apache Download Section and download Apache. I'm using Apache version 2.2.4 for this tutorial.

^^

TigerWarrior
02-01-2008, 03:12 AM
Can you install PHP under windows without installing any server application? I mean only to verify your code and check if its working?

Thanks?
TW

laserlight
02-01-2008, 04:22 AM
Can you install PHP under windows without installing any server application? I mean only to verify your code and check if its working?
Yes, but then you would be using the command line interface, and that may not be what you want for verifying web application code to check if it is working.

bpat1434
02-01-2008, 10:07 AM
With the CLI you can check for syntax errors. But just because there are no syntax errors doesn't mean the code will run as expected ;)

onionring9
02-12-2008, 05:13 AM
You might want to make a note for the newest version of apache (2.2.8) you will need to reference "php5apache2_2.dll" instead of "php5apache2.dll". Apache will not start if it is referencing the old apache dll.

bpat1434
02-12-2008, 09:24 AM
That's not entirely correct. The apahce 2.2.x line needs php5apache2_2.dll while the 2.0.x line will use the php5apache2.dll file. It's been this way since 2.2.0 ;)

And I plan on revamping this soon. Probably this weekend sometime.

bpat1434
02-26-2008, 10:49 PM
Updated the above steps with new images (finally I put them back up). Ran through them again myself and everything seems good.

muralikrishnan
08-29-2008, 02:45 PM
i am using xampp.....i am not anle to run phpscripts...my php version is 4....it is saying something like "something wrong with installation"...can anyone help//please?

bpat1434
08-29-2008, 03:14 PM
XAMPP is a software package, you'd have to ask support from them about installation. THis thread was for installing Apache, PHP, MySQL. Each being separate items, not installing through XAMPP or any other meta package like that.

muralikrishnan
08-29-2008, 03:27 PM
i am using xampp.....i am not anle to run phpscripts...my php version is 4....it is saying something like "something wrong with installation"...when i referred the net,it says that some path has to be changed in .conf in apache to php..i cant follow that...can anyone elaborate on that?

bpat1434
08-29-2008, 06:16 PM
Once again, ask on XAMPP's forums. This thread deals with installing the individual parts of the "AMP" installation (Apache, MySQL, PHP). We don't offer support for specific packages. I don't use XAMPP or WAMP.

If you want support for xampp, please go here (http://www.apachefriends.org/f/?language=english)

bpat1434
09-02-2008, 07:19 PM
Updated steps to fix a flub on my part. Added note about php5_apache2 vs php5_apache2_2 DLLs.

minifairy
10-24-2008, 05:52 PM
ok never mind I got this one... still working on upgrades though.

fluidblue
02-25-2009, 12:31 PM
I installed Apache v2.2.11 and PHP v5.2.8 (as module) exactly the way it was described.
Everything seems OK, I just tested phpMyAdmin and it worked.
But this script: http://www.evoluted.net/community/code/directorylisting.php doesn't work! I get the contents of the index.php file. Nothing is interpreted...

What am I doing wrong?

bradgrafelman
02-25-2009, 02:40 PM
You didn't do anything wrong; whoever wrote that script did a poor job doing it. Let's just say critiquing that script would take quite a while. :p

The main problem, however, is that the script uses short tag openings (e.g. '<?' or '<?=$var?>') even though these have been deprecated for some time and disabled by default. Change any instance of '<?' to '<?php' and '<?=$var?>' to '<?php echo $var ?>'.

fluidblue
02-25-2009, 04:20 PM
Thank you :)