If you are planning on using the oracle functions in PHP, you will need to install OCI8. Before you begin you will need to create an account with oracle or have access to the instant client basic install file and sdk file for your linux architecture.
Prerequisites for installing OCI8
- sudo (you will be doing the command line parts as sudo).
- An account on the oracle website so you can download the instant client files.
- A working Apache and PHP installation.
Installing the Oracle Instant Client Files
- Download the Oracle Instant Client for Linux (Both the Basic and SDK versions) from here. Make sure you choose the correct architecture for your Ubuntu installation (32bit is x86, 64bit is x86_64).
- Copy the files just downloaded to your Ubuntu server using scp or the WinSCP application for windows.
- ssh into your ubuntu server using your favorite ssh client
- Install PECL, PHP Development files, Build Essential, Unzip, and the AIO Library
apt-get install php-pear php5-dev build-essential unzip libaio1
- Create the oracle directory
mkdir /opt/oracle
- Move the downloaded files
mv instantclient-* /opt/oracle
- Unzip the files using the unzip command (unzip <filename>)
- Rename the created directory
mv instantclient_11_2 instantclient
- cd into the instant client directory and create the following soft links
ln -s libclntsh.so.11.2 libclntsh.so ln -s libocci.so.11.2 libocci.so
- cd to /opt
- set the permissions on the directory
chown -R root:www-data /opt/oracle
- Add the instant client to the the ld config files
echo /opt/oracle/instantclient > /etc/ld.so.conf.d/oracle-instantclient
- Update the Dynamic Linker Run-Time Bindings
ldconfig
Installing OCI 8 and Configuring Apache
- Install OCI8 using PECL
pecl install 0ci8
- When you are pompted for the client location enter the following:
instantclient,/opt/oracle/instantclient
- Add the extension to the php.ini files
echo extension=oci8.so >> /etc/php5/apache2/php.ini echo extension=oci8.so >> /etc/php5/cli/php.ini
- Restart Apache
/etc/init.d/apache2 restart
- Verify the installation of the OCI8 library by creating a simple phpinfo page.
touch info.php; echo "<?php phpinfo(); ?>" > info.php
- Navigate to the page using your favorite web browser and confirm the OCI8 section is present.
It removed my sudo permission!
Root has been taken over by http://www.data 😦
I think the following command was the culprit for which I am spending a very bad time now!
chown -R root:www-data /opt/oracle
Are you running apache as www-data? It’s usually run as this user. If you are, you should be all good.
If you aren’t, you could add the user to the www-data group.
The chown command shouldn’t remove you from the sudoers group it file. To add yourself back you can add them to the admin group or in the file /etc/sudoers
Or you can follow this guide http://benaiah41.wordpress.com/2008/08/15/37/
Muchas gracias, todo muy bien solo un par de detalles en estas lineas
ln -s libclntsh.so.11.2 libclntsh.so
ln -s libocci.so.11.2 libocci.so
en mi carpeta de descarga con la ultima version seria
ln -s libclntsh.so.11.1 libclntsh.so
ln -s libocci.so.11.1 libocci.so
y en
pecl install 0ci8
es
pecl install oci8
genial, muy bien detallado y funcional.
gracias por las felicitaciones y señalando mi error. Estás en lo cierto, los nombres de los archivos de la biblioteca dependen de versión.
I used google translator.. So the above maybe awkward.
Thank you! Works perfectly. I trying do this on OpenSUSE but with no luck. Now it’s done smoothly. You’ve made my day.
ERROR: `/tmp/pear/temp/oci8/configure –with-oci8=instantclient,/opt/oracle/instantclient’ failed
What version of the instantclient are you using? It is possible that a newer version has issues.
Other than that, and just to cover bases, are you running the setup using sudo? Also are there any more details about the error you can provide?
Caso o problema ocorra é só instalar gcc e gcc-c++ apt-get install gcc gcc-c++
thx, you saved my day!
hello, thank you very much. this tutorial so helpfull.
Excelente aporte me ha ayudado bastante