Oracle Instant Client on Ubuntu Dapper 6.06

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Oracle Instant Client on Ubuntu Dapper 6.06

Post by ^rooker »

This howto should provide step-by-step details of how to get php with OCI8 up and running, using Oracle's instant client - and NOT the full client install.

Info: This information is based on this article and this one.

I'm running Ubuntu Server (Dapper 6.06) on an ST20G5 shuttle PC - so I used the "Instant Client for Linux x86-64".

1) Download those files:
a) Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
instantclient-basic-linux-x86-64-10.2.0.2-20060228.zip (35,625,985 bytes) (cksum - 2403915938)

b) Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
instantclient-sdk-linux-x86-64-10.2.0.2-20060228.zip (602,431 bytes) (cksum - 1689085455)

(Optional, but valuable for debugging / testing):
c) Instant Client Package - SQL*Plus: Additional libraries and executable for running SQL*Plus with Instant Client
instantclient-sqlplus-linux-x86-64-10.2.0.2-20060228.zip (789,007 bytes) (cksum - 1598071762)


2) "cd" to to /opt/oracle/instantclient and unzip the files there.
2b) Create some symlinks which should be there, but aren't:

Code: Select all

n -s libclntsh.so.10.1 libclntsh.so
ln -s libocci.so.10.1 libocci.so
3) Download and compile the OCI8 package:

Code: Select all

pecl download oci8
tar -xzf oci8-1.2.2.tgz
cd oci8-1.2.2.tgz
phpize
./configure --with-oci8=shared,instantclient,/opt/oracle/instantclient
make
make install
4) Enable name resolving:

4a) set important environment variables.
(Here's a small script that will help testing)

Code: Select all

#!/bin/sh

LD_LIBRARY_PATH=/opt/oracle/instantclient:${LD_LIBRARY_PATH}
TNS_ADMIN=/etc/oracle
export LD_LIBRARY_PATH TNS_ADMIN
4b) Now create a tnsnames.ora in $TNS_ADMIN:

Code: Select all

mkdir -p $TNS_ADMIN
vi $TNS_ADMIN/tnsnames.ora
...and fill it with some meaningful content - like this:

Code: Select all

MYDB =
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = mymachine.mydomain)(PORT = 1521))
   (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = MYDB)
    )
  )
4c) Test if name resolving and connectivity works so far:
run:

Code: Select all

sqlplus username@MYDB
and check if you can connect to MYDB at all.

5) Let php know that it has a new extension:
In "php.ini" (/etc/php5/apache2/php.ini and /etc/php5/cli/php.ini), add a line

Code: Select all

extension=oci8.so
(put this line after the examples starting with ;extension).

6) Apache needs to know about the environment variables too, so change its startup script "/etc/init.d/apache2", by changing this:

Code: Select all

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
- to: -

Code: Select all

ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
ENV="$ENV TNS_ADMIN=/etc/oracle LD_LIBRARY_PATH=/opt/oracle/instantclient"
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Troubleshooting

Post by ^rooker »

[PROBLEM]
Running sqlplus gave me the following error:
Error 6 initializing SQL*Plus
Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
[SOLUTION]
check if $LD_LIBRARY_PATH is set correctly. mine was empty. :)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply