This tutorial should work for any recent version of the oracle instant client 9.0, 10.0, 10.1, 10.2, 11.1
I recommend that you run this after each step - that way you can see what errors you encounter and notice that they change and that therefore you are making progress
Code:
#!/usr/bin/env php
# instantclient_test.php
# Usage ORACLE_HOME=/opt/oracle/instantclient TNS_NAMES=ORACLE_HOME=/opt/oracle/instantclient/network/admin php instantclient_test.php
<?php
# Resources
# http://wiki.oracle.com/page/PHP+Oracle+FAQ
# http://download-west.oracle.com/docs/cd/B12037_01/network.101/b10775/naming.htm#i498306
# http://ubuntuforums.org/showthread.php?p=7581997
$username = 'user';
$password = 'secret';
$host = 'example.com';
$port = '1521';
$service_name = 'service.example.com';
$tns_service_name = 'TNSSERVICENAME';
echo "\nTesting OCI8\n";
echo "Connecting using dsn for Instant Client EZCONNECT: ";
oci_connect($username, $password, "//$host:$port/$service_name");
echo " No Exceptions! Yay!\n";
echo "Connecting using TNSNAMES service name: ";
oci_connect($username, $password, $tns_service_name);
echo " No Exceptions! Yay!\n";
echo "\n";
echo "\nTesting PDO_OCI\n";
echo "Connecting using dsn for Instant Client EZCONNECT: ";
$dbc = new PDO("oci:dbname=//$host:$port/$service_name", $username, $password);
echo " No Exceptions! Yay!\n";
echo "Connecting using TNSNAMES service name: ";
$dbc = new PDO("oci:dbname=$tns_service_name", $username, $password);
echo " No Exceptions! Yay!\n";
echo "\n";
?>
Install the Oracle Client
* All your bases are belong to Oracle (that's code for: You must register )
* Then download the instantclient and SDK from http://www.oracle.com/technology/sof...ent/index.html
Code:
sudo su -
mkdir -p /opt/oracle/instantclient
cd /opt/oracle/instantclient
# place oracle zip files here
unzip instantclient-basic-*-*.zip
unzip instantclient-sdk-*-*.zip
mv instantclient*/* ./
rmdir instantclient*/
# Just do this because I say so
ln -s libclntsh.so.* libclntsh.so
ln -s libocci.so.* libocci.so
echo /opt/oracle/instantclient >> /etc/ld.so.conf
ldconfig
# Set up your sqlnet.ora & tnsnames.ora
mkdir -p network/admin
cat - <<EOF > network/admin/sqlnet.ora
# sqlnet.ora Network Configuration File
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
EOF
cat - <<EOF > network/admin/tnsnames.ora
# TNSNAMES.ORA Network Configuration File
THETNSNAME =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = example.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = service.example.com)
)
)
EOF
* Now ready your Ubuntu box for oci8 (easier than php_pdo by far)
Code:
# run the test script
apt-get install --yes php5 php5-cli php5-dev php-db php-pear
apt-get install --yes build-essential libaio1
# run the test script
* Now here comes the hardest part, pay close attention: Ignore what the screen says and just do what I tell you. If you do this right you will only get 3 prompts. 2 shalt thou not answer except that thou proceedest to 3. 5 is right out.
Code:
pecl install oci8
# prompt 1: all
# prompt 2: shared,instantclient,/opt/oracle/instantclient
# prompt 3: [enter]
# skin a cat...
cat - <<EOF > /etc/php5/apache2/conf.d/oci8.ini
# configuration for php OCI8 module
extension=oci8.so
EOF
# And just because there's more than one way to skin a cat...
echo "# configuration for php OCI8 module" > /etc/php5/cli/conf.d/oci8.ini
echo "extension=oci8.so" >> /etc/php5/cli/conf.d/oci8.ini
# run the test script - it should work
* Installing pdo_oci is a little more tricky since it has not been updated since 2005
# First we have to fake it out because it's set up to work for the rpm installation of the client
Code:
cd /usr/include/
ln -s php5 php
cd /opt/oracle/instantclient
mkdir -p include/oracle/11.1/
cd include/oracle/11.1/
ln -s ../../../sdk/include client
cd -
mkdir -p lib/oracle/11.1/client
cd lib/oracle/11.1/client
ln -s ../../../../ lib
cd -
pecl channel-update pear.php.net
# I'm pretty sure it's safe to skip this step, but I did it
#pecl install pdo # this breaks pdo_mysql if you had it installed prior
#apt-get install libmysqlclient15-dev && pecl install pdo_mysql
mkdir -p /tmp/pear/download/
cd /tmp/pear/download/
pecl download pdo_oci
tar xvf PDO_OCI*.tgz
cd PDO_OCI*
##### Can't do this with cat #####
### copy the lines below into the file "config.m4.patch"
*** config.m4 2005-09-24 17:23:24.000000000 -0600
--- /home/myuser/Desktop/PDO_OCI-1.0/config.m4 2009-07-07 17:32:14.000000000 -0600
***************
*** 7,12 ****
--- 7,14 ----
if test -s "$PDO_OCI_DIR/orainst/unix.rgs"; then
PDO_OCI_VERSION=`grep '"ocommon"' $PDO_OCI_DIR/orainst/unix.rgs | sed 's/[ ][ ]*/:/g' | cut -d: -f 6 | cut -c 2-4`
test -z "$PDO_OCI_VERSION" && PDO_OCI_VERSION=7.3
+ elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.1; then
+ PDO_OCI_VERSION=11.1
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.10.1; then
PDO_OCI_VERSION=10.1
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.9.0; then
***************
*** 119,124 ****
--- 121,129 ----
10.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;
+ 11.1)
+ PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
+ ;;
*)
AC_MSG_ERROR(Unsupported Oracle version! $PDO_OCI_VERSION)
;;
#EOF
patch --dry-run -i config.m4.patch && patch -i config.m4.patch && phpize
ORACLE_HOME=/opt/oracle/instantclient ./configure --with-pdo-oci=instantclient,/opt/oracle/instantclient,11.1
make && make test && make install && mv modules/pdo_oci.so /usr/lib/php5/*+lfs/
cat - <<EOF > /etc/php5/apache2/conf.d/pdo_oci.ini
# configuration for php PDO_OCI module
extension=pdo_oci.so
EOF
cat - <<EOF > /etc/php5/apache2/conf.d/pdo_oci.ini
# configuration for php PDO_OCI module
extension=pdo_oci.so
EOF
Sanity check:
Code:
php --info | grep oci
I just did this all on a mostly fresh install of another system.
Guaranteed to work on 9.10 or your money back!
Bookmarks