Dec 27, 2012

Configuring PHP in Apache Http Server


WAMP setup Step by Step

Download Apache Http Server
Download Apache HTTP Server from location http://httpd.apache.org/download.cgi. For this tutorial we will be using Apache HTTP server 2.2.22 i.e. httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
Once downloaded install this server on local machine. Once installation is done following icon will appear on bottom right corner of your machine (if you are using windows OS). Going forward we will call this location APACHE_HOME, Save the location where Apache Httpd server is installed you will need this very frequently. (Simply create one .txt file to save all this info for time being, later you will by heart all this). In my case this location is C:\Program Files (x86)\Apache Software Foundation\Apache2.2
Hit the url http://localhost and welcome page of Apache as shown in Figure 1 should appear

Figure 1










Download PHP
Download latest version of php from http://www.php.net/downloads.php. In this tutoarial we are using latest stable version 5.4.6. Download and extract it on your local machine. Once archive is extracted, open command prompt and go to this location. Run simple command.
Note: There is a catch here download thread safe version and not non thread safe one.

Figure 2:






On command prompt it will give you some info and also this is a simple test to check that PHP running fine standalone on your local machine. Save this location too.

Figure 3















Copy php.ini-development file as php.ini.


Configure Apache with PHP
Go to APACHE_HOME/conf and save the original httpd.conf as httpd_original.conf so this file is not lost and can be restored if anything goes wrong. Now open this file for edit in your favourite editor.  (Mine is notepad++) and check for word LoadModule (or say section where all modules are loaded). At the end of this section add following lines
LoadModule php5_module "<PHP_HOME>/ php5apache2_4.dll"
AddHandler application/x-httpd-php .php

Also add following line to tell apache where php related configurations are
PHPIniDir "<PHP_HOME>"

Check in APACHE_HOME/conf/httpd.conf what is the value of DocumentRoot (by default this value in httpd.conf is set to APACHE_HOME/htdocs) lets call this value APACHE_DOC_ROOT. Now write a simple php file (hello.php) in APACHE_DOC_ROOT as follows
<?php
echo “Hello”
?>

Now hit the url http://localhost/hello.php Hello message should be shown as in Figure 4.

Figure 4