0 like 0 dislike
in Education & Reference by (3k points)

PHP Oracle Database Extension

  • OCI8 is the most available and scalable PHP adapter for the Oracle database. It is included with PHP, and is also separately downloadable for upgrading older PHP releases. OCI8 works with PHP 4 and PHP 5, and will compile with Oracle 9iR2, 10g and 11g client libraries. Oracle's standard cross-version compatibility and connectivity is applicable, so an OCI8 binary can connect to older or newer databases, locally or remotely.  
0 0
Use the OCI8 extension to access Oracle Database. Use 'pecl install
oci8' to install for PHP 7. Use 'pecl install oci8-2.0.12' to install
for PHP 5.2 - PHP 5.6. Use 'pecl install oci8-1.4.10' to install for
PHP 4.3.9 - PHP 5.1. The OCI8 extension can be linked with Oracle
client libraries from Oracle Database 12, 11, or 10.2. These
libraries are found in your database installation, or in the free
Oracle Instant Client from
Oracle's standard cross-version connectivity applies. For example,
PHP OCI8 linked with Instant Client 11.2 can connect to Oracle
Database 9.2 onward. See Oracle's note "Oracle Client / Server
Interoperability Support" (ID 207303.1) for details.

3 Answers

0 like 0 dislike
by (3k points)
Best answer
If you want to connect to an Oracle database with PHP, you can use Oracle's Instant Client and the oci8 module from pear.
Download the Basic and the SDK packages from http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html. At the time of this writing, the filenames are instantclient-basic-linux32- and instantclient-sdk-linux32-
Unzip these files in a new directory, e.g. /opt/oracle/instantclient.
mkdir -p /opt/oracle/instantclient
cd /opt/oracle/instantclient
unzip instantclient-basic-linux32-
unzip instantclient-sdk-linux32-
echo /opt/oracle/instantclient >> /etc/ld.so.conf
The previous two lines are supposed to create symlinks named libclntsh.so and libocci.so which we will need later. In my case these symlinks were not created by ldconfig, so I created them manually.
ln -s libclntsh.so.10.1 libclntsh.so
ln -s libocci.so.10.1 libocci.so
In the next step we will download the oci8 module with pear. Pear is in the php-pear package.
apt-get install php-pear
"Normally" we should be able to just use pear install oci8 now, but apparently pear is not able to figure out where the instantclient libraries are. So we will just download the oci8 module and build it on our own.
mkdir -p /usr/local/src
cd /usr/local/src
pear download oci8
tar xzf oci8-1.1.1.tgz
cd oci8-1.1.1
./configure --with-oci8=shared,instantclient,/opt/oracle/instantclient/
make install
The oci8-1.1.1.tgz filename will of course change for newer releases.
To enable the oci8 module in the php.ini (/etc/php.ini), add a line
extension=oci8.so (put this line after the examples starting with ;extension).
Now stop and start Apache. You should see the oci8 module in the output of phpinfo().
0 0
instead of "pear download oci8"
"pecl install oci8"
0 like 0 dislike

We will need 2 packages from Oracle ( 32 or 64 bit according to your machine )  - current Version – zip versions

  1. You can get the 2 downloads ( 32-bit ) from here http://www.oracle.com/technetwork/topics/linuxsoft-082809.html
  2. Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
  3. Unzip all files in this to a directory called /opt/oracle_instantclient ( of-course you can put it anywhere you like )
  4. Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
  5. Unzip this into the same directory /opt/oracle_instantclient
  6. Your /opt/oracle_instantclient directory must now contain all files from Instant Client Package – Basic and an SDK directory from Instant Client Package – SDK
  7. Next we need to create some symbolic links to “.so” files – you will see a file called libclntsh.so.version in /opt/oracle_instantclient  directory. In my case the file name is libclntsh.so.11.1. We will create a symbolic link named libclntsh.so  to the file  libclntsh.so.11.1  in the same directory using the command ln -s libclntsh.so.11.1 libclntsh.so
  8. Next we will install the php5-dev package command sudo apt-get install php5-dev
  9. Next we will install the package libaio using the command sudo apt-get install libaio-dev
  10. Then we install pear package using sudo apt-get install php-pear 
  11. Next, we will install the oci8 extension using sudo pecl install oci8 
  12. This will ask for Oracle Home Directory – give the path of the instant client instantclient,/opt/oracle_instantclient 
  13. In the above, we are telling pecl that its an instantclient and then giving the path to the instantclient directory
0 0
How to check a Server is 32 Bit or 64 Bit?
0 like 0 dislike


  1. If the installation is successful, you should see messages like “Build Process completed successfully”
  2. Add the oracle oci8.so to php.ini using
  3. sudo echo “extension=oci8.so” >> /etc/php5/apache2/php.ini 
  4. sudo echo “extension=oci8.so” >> /etc/php5/cli/php.ini 
  5. Be careful of double quotes in the above commands – dont copy paste from here – after executing, check your php.ini files
  6. ( Tip from Omar ) An alternative is to add this to the oci8.ini file using the command sudo echo “extension=oci8.so” > /etc/php5/conf.d/oci8.ini
  7. Restart apache using service apache2 restart 
  8. Open a web browser and navigate to the phpinfo file ( in my case it is localhost/phpinfo.php )
  9. Search for oci8 and you should find oci8 block with variables ( this means you have successfully compiled PHP with the oci8 extension )
  10. Next step is to test connecting to an oracle instance using oci_connect();
  11. Contact your Oracle DBA and get the following information hostname, port, service name, service type, username, password and then try out an example from http://www.php.net/manual/en/function.oci-connect.php
  12. If you get the error, oci_connect() is not defined, then something went wrong. Try looking at apache error logs or use php -v 


Related questions

1 like 0 dislike
1 answer 524 views
1 like 0 dislike
2 answers 2.8k views
1 like 0 dislike
1 answer 3.4k views
0 like 0 dislike
1 answer 2.6k views
0 like 0 dislike
1 answer 103 views
1 like 0 dislike
1 answer 163 views
0 like 0 dislike
1 answer 67 views
0 like 0 dislike
2 answers 99 views
0 like 0 dislike
1 answer 138 views