Friday, October 16, 2009

Integrating PHP in Apache in Plain English


I love the idea of open source (OS) software. And I am a keen promoter of it. But since my time is very restricted due to workload, I find it often very frustrating to install OS software. Sometimes I think the programmers and providers of the software tick along the motto: It was hard for us to program, so we make it hard for you to install and use.

However, some providers have come up with the idea of bundling loads of software together and install it either in one go or they use stack builders to add or update software (such as Postgres or osgeo with osgeo4w). While I find this idea commendable, I found that I ended up with several instances of Apache servers on my test machine. Which I find a bit over the top. So I had to start building the blocks by myself. Which was not always easy. As maybe other people do not either.

So I want to ease the pain of some other lay OS products users by giving some simple step by step guidance of how to integrate PHP 5.3.0 with Apache. 

Note: I assume that Apache is installed and running. Installing Apache is straight forward, use this link to download it. Make sure you get the latest stable version.

The environment I installed this combination of Apache and PHP 5.3.0 is Windows XP SP3 and Microsoft Server 2003 SE SP2.

So here's a step by step guide:


#DescriptionKeywords

Download the zip Version of PHP on download site above. Note: If you are using PHP with Apache 1 or Apache 2 from apache.org you need to use the VC6 versions of PHP. The direct link to the download is: http://windows.php.net/downloads/releases/php-5.3.0-Win32-VC6-x86.zip
Download

Extract the contents of the zip file into a new folder C:\PHP Install

Open the file C:\PHP\php.ini-production and save it as php.ini in the same directoryphp.ini

In php.ini, find short_open_tag = Off and set it to short_open_tag = On,

find magic_quotes_gpc = Off and set it On,

find ;session.save_path = /tmp unquote it (remove ;) and set it to
session.save_path = "C:\temp,save and exit php.ini
php.ini

Open C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.confand add the following line after all the LoadModule statements:

LoadModule php5_module "c:/php/php5apache2_2.dll"

httpd.conf

Search for "AddType" in the file, and add the following line after the last "AddType" statement. Do this no matter which version of Apache you are using. For Apache 2.2.x, you can find the "AddType" lines in the  section. Add the line just before the closing for that section.

AddType application/x-httpd-php .php

AddType application/x-httpd-php .phtml
httpd.conf
7
To indicate the location of your PHP ini file. Add the following line to the end of your httpd.conf file.  

PHPIniDir "c:/php"

This ensures that the correct database drivers are found. This is especially important with Postgres!
httpd.conf

As an alternative, the php.ini could be included in the environment variable PATH: „C:\PHP”
PATH

To get Postgres working with PHP, verify that the php_pgsql.dll file sits in the extension directory of PHP (in my case C:\PHP\ext). In the php.ini file, uncomment the extensions directory path and add the path where the extensions are located (in my case extension_dir = "C:\PHP\ext") and finally uncomment the extensions in the windows extensions section (extension=php_pgsql.dll)
PG connection

Relevant websites:

Integrating PHP 5.3.0 in Apache: http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml"

Downloading PHP: http://windows.php.net/download/

No comments: