Oracle on a Ubuntu Server
This page explains how to add Oracle support to PHP on Ubuntu servers, using OCI8 and PDO Oracle OCI drivers.
Dependencies
Before you continue:
- Install PEAR. Instructions are available on the Ubuntu Community Documentation.
Install the Oracle Instant Client and OCI8
First, download Oracle Instant Client 10.2. Once you click on the link for your system (Linux x86 or Linux x86-64), download the needed .zip files: basic and sdk.
Warning: Download the files from the 10.x branch, not from 11.x.
Once the archives are downloaded, open a terminal, move to the download folder and run the following commands as root to extract the files to the proper location:
mkdir -p /opt/oracle
cd /opt/oracle
unzip instantclient-basic-linux-*.zip
unzip instantclient-sdk-linux-*.zip
mv /opt/oracle/instantclient_10_2 /opt/oracle/instantclient
Then, run these commands to create some necessary symbolic links:
cd /opt/oracle/instantclient
ln -s libclntsh.so.10.1 libclntsh.so
ln -s libocci.so.10.1 libocci.so
Add the Oracle Instant Client to the ld of the system (needed for later):
su -echo /opt/oracle/instantclient > /etc/ld.so.conf.d/oracle-instantclient
Finally, compile oci8:
apt-get install php5-dev
apt-get install libaio libaio-dev
pecl install oci8
After you run the last command, you will be required to enter the following data: instantclient,/opt/oracle/instantclient
Install the PDO Oracle OCI Extension
The PDO Oracle OCI extension is distributed along with PHP, but is not supported by the PHP package available on the official Ubuntu repositories. Hence you will need to build PHP from source including that extension.
On a terminal, as root, run the following commands to retrieve the sources:
apt-get install build-essential debhelper fakeroot
apt-get build-dep php5
cd /usr/src
apt-get source php5
Then, you need to set up the environment:
export ORACLE_HOME=/opt/local/oracle/instantclient
export TNS_ADMIN=$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
Fix the include path references on the config.m4 file:
sed -e "s#/include/php/ext#/include/php5/ext#" -i php5-*/ext/pdo_oci/config.m4
You can now build and install PHP with the following commands:
phpize
./configure --with-pdo_oci=instantclient,$ORACLE_HOME,10.2
make
make install
Then you only need to enable OCI and PDO OCI on the PHP settings file (php.ini):
extension=oci8.so
extension=pdo_oci.so