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
- You must be logged in as root to perform this installation.
su root
- We will install PHP in /usr/local.
cd /usr/local
- Download the PHP source distribution php-3.0.7.tar.gz into this directory. Here is a list of mirrors.
- Uncompress the download with:
tar xzvf php-3.0.7.tar.gz
- 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
- First let's get where the action is:
cd php
- You now have 3 options:
- Simple PHP install without MySQL - goto step 3
- Simple PHP install with MySQL - goto step 4
- Simple PHP install without MySQL. Next, jump to step 6.
./configure --enable-track-vars
- 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.
- Now we can make the PHP executable. This will take a while.
make
- Now we install the PHP binary into our path with:
make install
Check that it Works
- Exit out of root, back to your normal user.
exit
- 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";
?>
- You can run this script using the command:
php < test
The output will look like this:
Content-type: text/html
hello world
- You can suppress the content type header by using the quiet option:
php -q < test
Giving this output:
hello world
- To get a list of all the available options use -h:
php -h
- 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