Configure Apache2 to work with PHP. Step by Step

Tuesday, April 03, 2007 |

First download Apache 2.0.59 and PHP.
Second install Apache, this has to be easy. Remember the path to the Apache main folder. Example:



Now open the httpd.conf that's located in the conf subfolder of Apache(Apache2\conf\httpd.conf).






Edit the directory to your web content. How to do this:
Go to Edit -> Find... and type:
DocumentRoot and press Enter or Find Next. Press cancel and replace the path in the quotes to the path of where you want your web content to reside on.
In example: "C:/my place/my site"
(look down in the image)
Press F3 to search again DocumentRoot, it's just a little down in the same page.
Look for: Directory Replace the path int the quotes with the path to your web content - it must be the same path as above. In example: "C:/my place/my site". Save and close.


Next step is to install php. Download the php archive and extract the files wherever you like. Keep in mind the path to the php main folder. Let's say you extract the files in C:\php , so here is where you will find php. Go to where you extracted the php files (e.g. C:\php). Cut the file named: php5ts.dll and paste it in C:\Windows
Go back to C:\php and rename the file php.ini-dist to php.ini Open it with Notepad. Find doc_root using Find (Ctrl+F) and type in the quotes the path to your web content, in our example it is "C:\my place\my site".

Find extension_dir with Find. Type in the quotes "C:\php\ext"

Save and close.

Open httpd.conf from the Apache subfolder conf (Apache\conf\httpd.conf)
Find LoadModule with Find. Go down until the LoadModule section ends. Insert a blank row and type like below but don't forget to replace path to your php folder to the path where you extracted php(e.g. C;/php):

LoadModule php5_module "path to your php folder/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "path to your php folder"
Example in this image:


Find AddType application/x-gzip .gz .tgz using Find, insert a blank row and type in these lines:

ScriptAlias /php/ "path to your php folder"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"
Save and close.
Example in this image:


Test php:
Open Notepad, go to File->Save As give the file name exactly as phpinfo.php (all php files must have the ".php" extension), select from Save As Type All Files and press Save. Type these lines:


I hope it works fine!

1 comments:

compadvice said...

Nice work,try to add more foto to your explains.:)See you