0 like 0 dislike

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.  
asked Aug 8, 2013 in Education & Reference by Marc (2,480 points) | 1,397 views
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
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().
answered Aug 8, 2013 by Marc (2,480 points)
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
answered Mar 13, 2014 by Hari
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 


answered Mar 13, 2014 by Hari

Related questions

1 like 0 dislike
1 answer
1 like 0 dislike
2 answers
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
asked Sep 7, 2017 in Education & Reference by Krish (880 points) | 17 views
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Aug 1, 2017 in Education & Reference by Krish (880 points) | 28 views
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Apr 18, 2014 in Education & Reference by Yogi (180 points) | 46 views

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

Mathe Forum Schule und Studenten
1,161 questions
1,297 answers
1,558 users