Installing PHP 4.x for Apache 1.x.x on Linux

by Nathan Wallace (Oct 25, 1999)
and John Brett (Dec 4, 2000)


This document describes how to install PHP for Apache on Linux. It was written using Red Hat 7.0, Apache 1.3.14 and PHP 4.0.3 patch level 1

You should have Apache installed before trying to install PHP. Here are my Apache installation instructions.

If you want to use PHP with MySQL then you must install MySQL first.

Before we Begin

  1. These instructions assume that you have Apache installed according to my instructions. That installation is done into /usr/local/etc/httpd and /www.

Getting PHP

  1. You must be logged in as root to perform this installation.
        su root

  2. You can get PHP4.0.3 patch level 1 from here. Here is a list of mirrors.
    Or you can ftp from
        cd php
        cd distributions
        get php-4.0.3pl1.tar.gz

  3. I save all my downloads in:
    If you don't already have one, you may need to create that directory now:
        mkdir /usr/local/downloads

Installing PHP

  1. We will install PHP in /usr/local/etc, but use a tricky tar command to do it in on hit from the download directory:
        cd /usr/local/downloads
        tar xzf php-4.0.3pl1.tar.gz -C ../etc

  2. Now we create a nice directory name (php) for the installed directory (php-4.0.3pl1):
        cd /usr/local/etc
        ln -s php-4.0.3pl1 php

Compiling PHP

  1. First let's get where the action is:
        cd php

  2. You now have 3 options:
    • Simple PHP install without MySQL - goto step 3
    • Simple PHP install with MySQL - goto step 4
    • Custom PHP install - goto step 5

  3. Simple PHP install without MySQL. Next, jump to step 6.
        ./configure --with-apache=../httpd --with-config-file-path=/www/conf --enable-track-vars

  4. Simple PHP install with MySQL. MySQL must be installed before you can configure PHP to use it. I recommend that MySQL should always be reachable with /usr/local/mysql. Even if you install it else where you should create a symbolic link from /usr/local/mysql. Otherwise the compiler can have problems finding the mysqlclient library. The command should look like this:
        ./configure --with-mysql=/usr/local/mysql --with-config-file-path=/www/conf --with-apache=../httpd --enable-track-vars
    Next, jump to step 6.

  5. Custom PHP install. Take a look at the available configuration directives by using this command:
        ./configure --help

  6. Now we can make the PHP executable. This may take a while.

  7. Now we install the PHP module with:
        make install

Adding the PHP Module to Apache

  1. Now we have to setup Apache to include the PHP module:
        cd ../httpd

  2. Re-configure Apache to use the PHP module. You should use your previous Apache configure command along with the PHP activate module directive. You can see your previous Apache configure command by doing:
        cat config.status
    You can configure Apache using the previous command with the added PHP module by doing:
        ./config.status --activate-module=src/modules/php4/libphp4.a
    If you used the simple Apache install from my instructions this will effectively perform this:
        ./configure --prefix=/usr/local/etc/httpd --sysconfdir=/www/conf \
            --activate-module=src/modules/php4/libphp4.a --enable-module=status \
    	--enable-module=rewrite --enable-module=status

  3. Make Apache with PHP enabled:

  4. Now shut down Apache and install before starting again:
        /usr/local/etc/httpd/bin/apachectl stop
        make install
        /usr/local/etc/httpd/bin/apachectl start

Setting Up PHP

  1. PHP has created an ini file. We have to install this into it's correct location.
        cd ../php
        cp php.ini-dist /www/conf/php.ini

  2. We have to tell Apache to pass certain file extensions to PHP. We do this in Apache's httpd.conf file.
        cd /www/conf
  3. Edit the httpd.conf file. If you do a search for php you will find a couple of commented out lines telling Apache to use the PHP module. You should uncomment them to look like this.
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

  4. I prefer to use the extension .phtml, you can use whatever extension you like (even .html) by adding lines to httpd.conf like this:
    AddType application/x-httpd-php .phtml

Check that it Works

  1. We have to restart Apache to make these changes take effect on the running server.
        cd /usr/local/etc/httpd/bin
        ./apachectl restart

  2. Apache should now be running with PHP enabled. The server version should include PHP/4.0.3pl1.
        ./apachectl status
                    Apache Server Status for
    Server Version: Apache/1.3.14 (Unix) PHP/4.0.3pl1
    Server Built: Dec 4th 2000 13:31:09

  3. Now it is time to test PHP with a page. The simplest thing to do is create a page in one of your virtual servers (eg: called test.php. My file is here (link removed). This file contains the following text:
    <?php phpinfo(); ?>

  4. Point your browser at this file on the virtual host which you used:

  5. The results should look something like this (link removed).