Oracle Instant Client and PHP OCI8 on Debian Squeeze


Because there is no deb package for PHP OCI8 for Debian, here is a simple tutorial how to install Oracle Instant Client and use PHP OCI8 on Debian Squeeze.

Install dependencies and required packages

This will install Apache with PHP5 support and all required packages to configure OCI8.

aptitude install php-pear php5-dev build-essential unzip libaio1

Download the software from Oracle website where you will need a Oracle account. You can create one for free if you don’t have one. Go to this link and choose your platform: http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

You need yo download the following packages:

Instant Client Package - Basic
Instant Client Package - SDK

Now we are going to create the location where we are going to store Oracle Instant Client files

mkdir -p /opt/oracle/instantclient
cd /opt/oracle/instantclient
unzip instantclient-basic-linux.x64-11.2.0.3.0.zip
unzip instantclient-sdk-linux.x64-11.2.0.3.0.zip
mv instantclient_11_2/* ./
rm -r instantclient_11_2/ instantclient-basic-linux.x64-11.2.0.3.0.zip instantclient-sdk-linux.x64-11.2.0.3.0.zip

Now we need to create the missing simlinks

ln -s libclntsh.so.11.1 libclntsh.so
ln -s libocci.so.11.1 libocci.so

Now we are going to install the PHP part and OCI8 package

pecl install oci8 (when asked for ORACLE_HOME directory type: instantclient,/opt/oracle/instantclient)

At the and load OCI8 as extension and restart apache

echo "extension = oci8.so"> /etc/php5/conf.d/oci8.ini
/etc/init.d/apache2 restart

You should now be able to see OCI8 as module in phpinfo() or type:

php-i | grep oci

you will get:

oci8
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20

Also the easiest way i’ve found to connect to a remote Oracle database is with this code:

<?php
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.XX.XXX)(PORT = 1521)))(CONNECT_DATA=(SID=XXXX)))";
$c1 = oci_connect("name","password",$db);
?>

I hope this will help you and here are some related links:

PHP OCI8 manual: http://php.net/manual/en/book.oci8.php
Oracle Database: http://www.oracle.com

 



Subscribe
Notify of
guest
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
sarmad
11 years ago
Dennis
11 years ago

Nice information

Brian
Brian
11 years ago

Fantastic. Thank you.

korny
korny
10 years ago

Super, thank you!

Paulo Lucio Oliveira Junior
Paulo Lucio Oliveira Junior
10 years ago

Thank you very much.
Just for the record what happened to me. If you’re going to download oci8 using a proxy address, just use: pear config-set http_proxy address:port.

After that, you can use: pecl install oci8

Bilal
Bilal
10 years ago

The approach i nice but there are many many error in the document. The unix command need a recheck.

Cristian Martín
9 years ago

Thanks so much, this post helped me many times!

Hot Episode
Hot Episode
8 years ago

Advertisement