Andrew Watson's Homepage

andrewwatson.net › IT › Installation Guides › Installing PHP as a compiled Apache module with PostgreSQL Support

Installing PHP as a compiled Apache module with PostgreSQL Support

Also available as
I normally perform the following su'd as root unless otherwise noted

Note: Requires Apache non-DSO or Apache DSO and PostgreSQL to be already installed

Step 1: make the directory, if it does not already exist, to put the tarball and source tree into
mkdir /usr/local/src/php
Step 2: get the tarball, either from www.php.net or from a local source
download or copy <phpversion>.tar.gz to /usr/local/src/php
Step 3: unzip and untar the tarball
cd /usr/local/src/php
tar zxvf /usr/local/src/php/<phpversion>.tar.gz
cd /usr/local/src/php/<phpversion>
the above will unzip and untar the tarball into the required directory tree

Step 4: configure the makefile ready to compile
./configure --with-apache=/usr/local/src/apache/<apacheversion> \
                 --with-pgsql=/usr/local/pgsql
with-apache sets Apache support and path to Apache source tree (I think it's the source tree that need to be pointed to, either that or the binary tree which will be /usr/local/apache/<apacheversion>)
with-pgsql sets PostgreSQL support and path to PostgreSQL binary tree


Step 5: do the compile and the install
make && make install
Step 6: re-configure the Apache makefile
cd /usr/local/src/apache/<version> ./configure --verbose \
                 --prefix=/usr/local/apache/<version> \
                 --enable-module=info
                 --activate-module=src/modules/php3/libphp3.a
verbose is enabled just-for-the-hell-of-it™
prefix defines the base directory to install into, e.g. /usr/local/apache/1.3.11 I also usually add php to the end /usr/local/apache/1.3.11_php
enable-module=prefix is again installed just-for-the-hell-of-it™, plus it provides lots of extra exciting info when the server is running
activate-module=src/modules/php3/libphp3.a activates the PHP module and provides the path to the module


Step 7: do the compile and the install again for Apache
make && make install
Step 8: copy the configuration file on to the target system
cd /usr/local/src/php/<phpversion>
cp php3.ini-dist /usr/local/lib/php3.ini
Step 9: edit httpd.conf
cd /usr/local/apache/<apacheversion>/conf
add following to httpd.conf using prefered editor:
AddType application/x-httpd-php3 .php3
the above line is often already entered into httpd.conf but commented out, scan down the file and find it

Step 10: restart Apache
/usr/local/apache/<apacheversion>/bin/apachectl stop /usr/local/apache/<apacheversion>/bin/apachectl start
you should now have a working Apache server with PHP

Step 11: test Apache
telnet <hostname> <port>
HEAD / HTTP/1.0<CR><CR>
Should return a line like following:
Server: Apache/1.3.11 (Unix) PHP/3.0.15
telnet <hostname> <port> where <hostname> is the hostname of the machine Apache & PHP are installed and running on and <port> is the number of the port that Apache is running on, usually 80, but sometime 8080, configurable via httpd.conf

See Also:PHP Official Documentation - Chapter 3: Installation, Related Links
Andrew Watson (email)
Last Modified: Wednesday, 03-May-2006 20:51:48 CEST