Installing PHP and the Oracle Oci8 extension
This post is the right and updated procedure to install the PHP Oci8 extension with the Oracle instant client on Linux (Ubuntu, Kali, Debian distributions). That's because I have spent a lot of time finding the right steps and combinations. The procedure seems very long but I ensure you will not need more than 10 minutes! I started installing PHP just to be sure all were OK. Very important: do all operations logged as root!
With the first command, you will install PHP. The other commands are here to edit the php.ini files:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
The PHP extensions will be on the following path. Go to /usr/lib/php5 and check the dir with the number like this:
Now we will add some required enviroment variables:
sudo gedit /etc/environment
Oracle instant client
Download the Oracle instant client from the Oracle website. You will need an account. It is very important to choose the right version 32 or 64 bit or the client will not work on your computer! Download both the client and the sdk. Maybe you will need sqlplus too but to be host I have tried to install it and it doesn't work for me! Unzip the client and the SDK on /opt/oracle/instantclient (creating the directory oracle: mk dir oracle) You can give right the permissions on this new directory or use the tar command to unzip the files. Be sure to copy the sdk folder inside the instanclient directory (rename the directory instantclient_12 to instantclient manually or from the shell). Add the enviroment variables: gedit /etc/enviroment
Now you need to create 2 symbolic links. They are very important too:
ln -s libclntsh.so.11.2 libclntsh.soln -s libocci.so.11.2 libocci.so
Install PEAR and PECL
Yes, i know it: PEAR is now obsolete and we all use composer but in this case we can't use it, so:
sudo apt-get install php-pearsudo apt-get install php5-devsudo apt-get install php5 php5-dev php-pear php5-clisudo apt-get install libaio1
Now export the PHP_DTRACE variable and launch the installation with pecl:
export PHP_DTRACE=yespecl install -f oci8-1.4.10
When the prompt will ask you the path, type: shared,instantclient,/opt/oracle/instantclient,$ORACLE_HOME Now edit both php.ini files and add the extension: extension=oci8.so Edit both php.ini files:
sudo gedit /etc/php5/apache2/php.inisudo gedit /etc/php5/cli/php.ini
sudo /etc/init.d/apache2 restart
Check the PHP extension list:
Now you must see the oci8. If not, there were something wrong... I hope this will be useful if you need this extensions. For me it's the most complex extension to install on PHP.
The installation can be totally different on Windows so I am sorry to say I have not tried to install this extension on Windows. It is highly recommended to install and use this extension instead pdo for Oracle.