HOWTO
Revision: 2
Updated: Nov 10, 2005
Problem
You want to have a single apache webserver able to serve up both PHP4 and PHP5
without resorting to proxies, weird filename extensions (.php4/.php5)
or using nonstandard ports (:8080).
Solution
The machine was running mod_php4 with Apache 1.3.x
and i was looking for a way to get apache to also use
PHP5 to serve up files
out of certain directories (or vhosts)
Because i couldn't just replace PHP4 with PHP5 for all sites on the server,
i needed to find a way to use PHP4 (module) on some sites
and PHP5 (CGI) on other sites using a single apache install.
I wanted it to be completely transparent to the user and to
each of the vhosts on the machine
(meaning no proxies, port redirection or filename extension hints).
I chose to build PHP5 from the source-code rather than use one of the
precompiled debian mod_php5 packages, becuase i am pretty sure that
trying to use both mod_php4 and mod_php5 in the same apache instance
would cause some bad conflicts, and at the time there weren't
any PHP5 packages in 'testing'.
1. Prerequisites
First, think about which extentions you want to use with PHP and install the
appropriate dev / client / library packages for debian.
In my case, becuase i wanted MySQL support in PHP5, i needed to install the
MySQL development libraries along with bison and flex and libxml2 (becuase
configure complained about those as well).
apt-get install libmysqlclient-dev bison flex libxml2-dev
2. Download and install PHP5
Fetch a fresh copy of the PHP5 source code from the
PHP site.
Unzip, configure and install it:
./configure --prefix=/usr/local --with-mysql=/usr/include/mysql/ && make && sudo make install
When it's done installing, test that it works on the command line.
3. Configure apache
Symlink the PHP5 binary into the cgi-bin directory.
You can just copy the 'php' binary over to the directory too,
but this makes upgrading more of a pain, because you'll have
to remember to copy the binary everytime.
On a linux system, the command would look like:
ln -s /usr/local/bin/php /usr/lib/cgi-bin/php5
On an OS X system, might look like:
ln -s /usr/local/php5/bin/php /Library/WebServer/CGI-Executables/php5
Then, anable the mod_actions module so that you can use the "Action"
keyword in the "Directory" stanza below. On debian, this can be
done very easily with:
apache-modconf apache enable mod_actions
Now you should be able to simply use <Directory> entries to tell apache
which directories to parse with PHP5. Directories that you don't explicitly
tell apache to use php5, it will default back to mod_php4:
<Directory /your/php5/files/>
AddHandler php-script .php
Action php-script /cgi-bin/php5
</Directory>
Notes
Software referenced