Install Oracle on Linux with Apache/PHP

by Hans Schou <>

How to install Oracle 8.0.5 on Red Hat 5.2

Documentation is like sex. When it is good, it is very very good. When it is bad, it is better than nothing.
-- Bruce Perence

If my description is too short then go look at

When installing Red Hat 5.2 all package which is about C development should be installed.

This example describe how to do a simple installation. A real installation should be made acording to the OFA standard (PDF-file 350KB).

Insert the Oracle CD-ROM and login as root.

# set 'oracle' as owner
export ORACLE_OWNER=oracle
# add a group named 'dba'
groupadd dba
# add a user named 'oracle'
useradd -g dba oracle
# change password for oracle
passwd oracle
# Change mode on '/home/oracle' if you will run Apache/PHP
chmod 755 /home/oracle
# Create '/etc/oratab'
echo ORCL:/home/oracle:Y > /etc/oratab
# Change owner
chown oracle:dba /etc/oratab
# ..and permission
chmod 664 /etc/oratab
# Give all users access to run Oracle apps.
echo export ORACLE_HOME=/home/oracle >> /etc/profile
echo export ORACLE_BASE=/home/oracle >> /etc/profile
echo export ORACLE_SID=ORCL >> /etc/profile
echo export LD_LIBRARY_PATH=/home/oracle/lib >> /etc/profile
# If your main Oracle server is on a remote machine, then...
echo export TWO_TASKS=ORCL >> /etc/profile
# Mount the Oracle CD
mount /dev/cdrom /mnt/cdrom
# Login as 'oracle'
su - oracle

You are now loged in as oracle and the installation can begin.

# Go to install directory
cd /mnt/cdrom/orainst
# Start installation
# Just install the 'default'
# Modules:
#  C/C++ Precompilers
#  SQL*Plus

# I have had some problems with the default tnsnames.ora
# Try this one:
# Change 'localhost' to your hostname
cd /home/oracle
echo "ORCL=(DESCRIPTION=" > network/admin/tnsnames.ora
echo " (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))" >> network/admin/tnsnames.ora
echo " (CONNECT_DATA=(SID=ORCL))" >> network/admin/tnsnames.ora
echo ")" >> network/admin/tnsnames.ora

# If your hostname is 'localhost', only users which is on the
# system can get a connection to Oracle. A smart trick if only
# PHP should use Oracle.

Test the installation. Login as 'oracle'

# Start Oracle Database
# Start the listener
lsnrctl start
# List current users
sqlplus system/manager <<EOF
select osuser, program from v\$session;

Shutdown Oracle

# Login as 'oracle' and shutdown
# Stop the listener if you like
lsnrctl stop

Install/compile Apache/PHP

PHP runs Oracle very fast. You must check it out despite that it takes much more time to develop an app. in PHP than Oracle WebDB. This is a "must try".

# Login as 'root' to get the environment from /etc/profile
# Pre-run 'configure' in apache
cd /usr/src/apache
# Go to your PHP directory (php-3.0.5 works fine)
cd /usr/src/php
# Run 'configure' with your favourit parameters like "--with-gd" etc.
# (PHP runs faster as a module than as a CGI)
./configure --with-oracle --with-apache=../apache --enable-track-vars
# Make the thing
# Install the module in apache
make install
# Go to Apache (apache_1.3.2 and later works fine)
cd ../apache
# Configure Apache
# (apache_1.3.4 has the option '--layout=GNU'. I guess it is better)
./configure --with-layout=GNU --activate-module=src/modules/php3/libphp3.a
# you gonna make it
# and install it
make install
# Activate PHP in Apache
# Go to your 'conf' directory
cd /usr/local/apache/etc
# edit srm.conf
vi srm.conf
# find the section with PHP in 'srm.conf'
/php (this is a 'vi' command ;-)
# remove the '#' from the following lines in 'srm.conf'
#AddType application/x-httpd-php3 .php
#AddType application/x-httpd-php3-source .phps
# exit 'vi' (or whatever editor you use)
# Fire up Apache (Apache will get the environment from /etc/profile)
# If you have stopped Oracle then start it now
# Download a simple example and place it here
/usr/local/apache/share/htdocs/whoison.php (or who.php for OCI-calls)
# Test 'whoison.php' with your favourit browser
# User name: system (option: system@ORCL)
# Password: manager (I better change it one day)
lynx localhost/whoison.php
# If it doesnt work, lookup your hostname in $ORACLE_HOME/network/admin/tnsnames.ora
lynx `hostname`/whoison.php
# begin your big project
vi big_fat_app.php

Learn more?

OFA - Optimal Flexible Architecture

On first sigth the OFA standard looks like a mess but when you are going to mount the next disk, create another SID or upgrade the software you will like it.

When running 'orainst' you will have one difficult question:
 There is already a SID running with the same name
Answer YES.

# Login as root
#mount /dev/sdg1 /u01 -- or whatever harddisk you have
# if you only have one HD then:
if test -d /u01; then
echo "got /u01"
mkdir /u01
if test -d /u02; then
echo "got /u02"
mkdir /u02
if test -d /u03; then
echo "got /u03"
mkdir /u03
# above: if you install a new HD later it is easy to mount on one of the above
# set 'oracle' as owner
export ORACLE_OWNER=oracle
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/8.0.5
# add a group named 'dba'
groupadd dba
# add a user named 'oracle'
useradd -g dba $ORACLE_OWNER
# give 'oracle' access to the mount points
chown $ORACLE_OWNER:dba /u0?
# Insert variables into oracle's .bash_profile
echo "#-- start inserted by root --" >> /home/$ORACLE_OWNER/.bash_profile
echo export ORACLE_SID=$ORACLE_SID >> /home/$ORACLE_OWNER/.bash_profile
echo export ORACLE_BASE=$ORACLE_BASE >> /home/$ORACLE_OWNER/.bash_profile
echo export ORACLE_HOME=$ORACLE_HOME >> /home/$ORACLE_OWNER/.bash_profile
echo export ORACLE_DOC=$ORACLE_BASE/doc >> /home/$ORACLE_OWNER/.bash_profile
echo export LD_LIBRARY_PATH=$ORACLE_HOME/lib>>/home/$ORACLE_OWNER/.bash_profile
# If your main Oracle server is on a remote machine, then...
echo export TWO_TASKS=ORCL >> /home/$ORACLE_OWNER/.bash_profile
# extend the PATH
echo PATH=\$PATH:\$ORACLE_HOME/bin >> /home/$ORACLE_OWNER/.bash_profile
echo "#-- end inserted by root --" >> /home/$ORACLE_OWNER/.bash_profile
# Mount the Oracle CD
mount /dev/cdrom /mnt/cdrom
# run the root script
sh /mnt/cdrom/orainst/
# add the SID to oratab
echo $ORACLE_SID:$ORACLE_HOME:Y >> /etc/oratab
# Login as $ORACLE_OWNER
su - $ORACLE_OWNER -c "cd /mnt/cdrom/orainst; ./orainst"
echo "*** Oracle installation completed ***"
echo "A good idea to give '$ORACLE_OWNER' a password"
#passwd oracle

Sub-directories used by PHP during compilation:

No go

I have tried to install Oracle for Linux on SuSE 5.3, Slackware 3.4 and Red Hat 5.1 without success. I had the right version of bash, glibc, gcc and so on, but for some reason it would not install.