Pages

Run PHP5 on Apache2.2.x as Module or CGI

This is a notes on how to run PHP5 on Apache 2.2 with either Module or CGI.

Open Apache http.conf file and make the following changes.

The following modification is only required for run PHP as CGI.
1. Find the default directory section
<Directory />
Options FollowSymLinks
AllowOverride None
#Order deny,allow
#Deny from all
Satisfy all
</Directory>


Comment out the following two lines
Order deny,allow
Deny from all

2. Add the following lines for Module or CGI
# RUN PHP as Module

PHPIniDir "D:/php5/"
LoadModule php5_module "D:/php5/php5apache2_2.dll"
AddType text/html .php .php5
AddHandler application/x-httpd-php .php . php5

# RUN PHP as CGI
ScriptAlias /php/ "C:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php-cgi.exe"
<Directory />
Order allow,deny
Allow from all
</Directory>

Apache2.2 + PHP5

The purpose of this post is to run Apache2.2.x + PHP5 on Windows XP.

The goal is be able to run mod_rewrite module and load PHP5 by deafult. Due to the file system. use .htacess is not good idea. So I will be using htaccess.txt for Windows system.


Add the following to the http.conf under Apache 2.2 installation:
LoadModule php5_module "D:/php5/php5apache2_2.dll"

# configure the path to php.ini
#PHPIniDir "D:/php5" <-- This line seem to be unnecessary

AccessFileName htaccess.txt
<files>
order allow,deny
deny from all
</files>


Alias /wwwroot "D:/wwwroot/"
<directory>
Options Indexes MultiViews
AllowOverride FileInfo <--- Can simply set to ALL to allow custom htaccess.txt
Order allow,deny
Allow from all

AddType text/html .php .php5
AddHandler application/x-httpd-php .php . php5
</directory>
===============
Add the following line to htaccess.txt to automatically add trailing slash /

<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>