Installing Oracle support for php5 turned out to be hell! So here is what i did.
System was Ubuntu 10.04 x86_64 but i imagine same things goes for i386 you just need to find the appropriate Oracle Instant client files.
First you need to download the following zip files from Oracle:
oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip
oracle-instantclient11.2-sqlplus-11.2.0.1.0-1.x86_64.zip
oracle-instantclient11.2-sdk-11.2.0.1.0-1.x86_64.zip
Then you need to unpack these to /opt
sudo unzip oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip -d /opt
sudo unzip oracle-instantclient11.2-sdk-11.2.0.1.0-1.x86_64.zip -d /opt
sudo unzip oracle-instantclient11.2-sqlplus-11.2.0.1.0-1.x86_64.zip -d /opt
Then we need to set important environment variables (You would wan't to add this tou your .bashrc):
export TNS_ADMIN=/opt/instantclient_11_2
export SQLPATH=instantclient_11_2
export LD_LIBRARY_PATH=/opt/instantclient_11_2:$LD_LIBRARY_PATH
export PATH=$PATH:$SQLPATH
We move to the directory containing our newly created files:
cd /opt/instantclient_11_2/
Then we need to hax a bit to ensure that this lib is found correctly by pecl:
mv libclntsh.so.11.1 libclntsh.so
ln -s libclntsh.so libclntsh.so.11.1
If you don't do the step above you will most likely get this error below:
checking Oracle Instant Client version... configure: error: Link from /opt/instantclient_11_2/libclntsh.so to libclntsh.so.11.1 not found
ERROR: `/tmp/pear/temp/oci8/configure --with-oci8=instantclient,/opt/instantclient_11_2' failed
Now if you don't already have apache2.2 and php5 and the other packets below you need to get and install them so:
apt-get install php-pear php5-dev apache2.2-common libapache2-mod-php5 php5
Time to finally install oci8:
pecl install oci8
You will be asked to input the path to the ORACLE_HOME directory:
Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] :
So you provide it by pasting in this:
instantclient,/opt/instantclient_11_2
Then you add the oci8 extension to you apache2 and or client php.ini files:
echo 'extension=oci8.so' >> /etc/php5/apache2/php.ini
echo 'extension=oci8.so' >> /etc/php5/cli/php.ini
And restart apache2:
sudo /etc/init.d/apache2 restart
Make a quick oci8test.php in your wwwroot and try the oci_connect function to test if it works:
$c = oci_connect('USER', 'PASS', 'DBHOST/ServiceID');
It does not really matter if you have created a user/schema yet as long as you dont get some error like this in the apache error log when running the php script in a browser, your done installing oci8 support!
PHP Fatal error: Call to undefined function oci_connect() in /var/www/oci8test.php on line 3
NB! If you get this
root@linux:~# php
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/oci8.so' - libaio.so.1: cannot open shared object file: No such file or directory in Unknown on line 0
You need to install libaio1:
sudo apt-get install libaio1
I wan't to thank these bloggers for their contribution although i didn't understand anything but the commands in nr2 link!
http://computergyan.wordpress.com/2010/08/03/installing-php-oci8-with-oracle-xe-in-ubuntu-10-04-x86-64/
http://zital.hackinbadakigu.net/?p=31
http://ervanmardianto.com/installing-oci8-on-debian-i686
If you are learning to work with Oracle and PHP you also might wan't to check out these links!
PHP.net oci8 manual
The Underground PHP and Oracle Manual
The Oracle 10g express edition server (FREE)
August 26, 2010 at 7:51 am
Thank you!
I’v tried to solve this problem for hours and got a great help from you!
August 26, 2010 at 8:53 am
No problem that was the reason for this blog, i usually just move on after solving something. But thought it would be nice to share the “fruit” with others.
August 9, 2011 at 6:13 pm
I have followed the instructions to a tee [copy & paste], but when I try to run the pecl install oci8 command I am getting an error:
/usr/bin/ld: skipping incompatible /opt/instantclient_11_2/libclntsh.so when searching for -lclntsh
/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
make: *** [oci8.la] Error 1
ERROR: `make’ failed
HELP please.
[I am running Ubuntu-10.04.3-desktop-i386]
August 9, 2011 at 8:42 pm
Nevermind. I was copy and pasting too much since I was trying to use the 64bit on my 32bit system. It works when you actually follow the directions instead of blindly C&P’ing.
September 16, 2011 at 10:17 am