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

by Nathan Wallace (Oct 25, 1999)

Introduction

This document describes how to install PHP for Apache on Linux. It was written using Red Hat 6.1, Apache 1.3.9 and PHP 3.0.12.

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. I save all my downloads in:
        /usr/local/download
    
    If you don't already have one, you may need to create that directory now:
        mkdir /usr/local/download
    

  3. You can get PHP 3.0.12 from here. Here is a list of mirrors. Here are the ftp commands:
        cd /usr/local/download
        ftp ftp.php.net
        cd pub/distributions
        bin
        get php-3.0.12.tar.gz
        bye
    

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/download
        tar xzf php-3.0.12.tar.gz -C ../etc
    

  2. Now we create a nice directory name (php) for the installed directory (php-3.0.12):
        cd /usr/local/etc
        ln -s php-3.0.12 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.
        make
    

  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/php3/libphp3.a
    
    If you used the simple Apache install from
    my instructions the command will look like this:
        ./configure --prefix=/usr/local/etc/httpd --sysconfdir=/www/conf --activate-module=src/modules/php3/libphp3.a
    

  3. Make and install Apache with PHP enabled:
        make
    

  4. We need to stop the server before installing the files:
        bin/apachectl stop
    

  5. Now we can install the new binaries:
        make install
    

  6. Start apache again (now running the new php enabled version):
        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 php3.ini-dist /www/conf/php3.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-php3 .php3
    AddType application/x-httpd-php3-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-php3 .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/3.0b2.
        ./apachectl status
    
                    Apache Server Status for dev.synop.com
                                           
    Server Version: Apache/1.3.9 (Unix) PHP/3.0.12
    Server Built: Oct 25 1999 00:37:07
    
    ...
    

  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: dev.synop.com) called test.php3. 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:
        http://dev.synop.com/test.php3
    

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