Installing PHP 3.x Scripting on Red Hat Linux 5.x

by Nathan Wallace (September 17, 1999)

Introduction

This document describes how to install PHP command line scripting on Red Hat Linux.

If you want to use PHP as an Apache module you should use these instructions.

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

You can have both the module and cgi / command line versions of PHP installed simultaneously. If you have already installed the module version you can jump straight down to the Compiling PHP section. It will have no ill effects on your module installation.

Installing PHP

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

  2. We will install PHP in /usr/local.
        cd /usr/local
    

  3. Download the PHP source distribution php-3.0.7.tar.gz into this directory. Here is a list of mirrors.

  4. Uncompress the download with:
        tar xzvf php-3.0.7.tar.gz
    

  5. Now we create a nice directory name (php) for the installed directory (php-3.0.7):
        ln -s php-3.0.7 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

  3. Simple PHP install without MySQL. Next, jump to step 6.
        ./configure --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 --enable-track-vars
    
    Next, jump to step 6.

  5. Now we can make the PHP executable. This will take a while.
        make
    

  6. Now we install the PHP binary into our path with:
        make install
    

Check that it Works

  1. Exit out of root, back to your normal user.
        exit
    

  2. Now we are going to create a simple php script. Save the following into a file called test:
        <?php
        $a = 'world';
        echo "hello $a\n";
        ?>
    

  3. You can run this script using the command:
        php < test
    
    The output will look like this:
        Content-type: text/html
    
        hello world
    

  4. You can suppress the content type header by using the quiet option:
        php -q < test
    
    Giving this output:
        hello world
    

  5. To get a list of all the available options use -h:
        php -h
    

  6. Now we will create a script that is executable:
        #!/usr/local/bin/php -q
        <<php
        $a = 'world';
        echo "hello $a\n";
        ?>
    
    Now make it executable:
        chmod +x test
    
    and run it:
        ./test