Claim your Biolink Click Here
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.  
in Education & Reference by (4.7k points) | 2.7k views
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
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 At the time of this writing, the filenames are and
Unzip these files in a new directory, e.g. /opt/oracle/instantclient.
mkdir -p /opt/oracle/instantclient
cd /opt/oracle/instantclient
echo /opt/oracle/instantclient >> /etc/
The previous two lines are supposed to create symlinks named and which we will need later. In my case these symlinks were not created by ldconfig, so I created them manually.
ln -s
ln -s
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 (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().
by (4.7k points)
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
  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 in /opt/oracle_instantclient  directory. In my case the file name is We will create a symbolic link named  to the file  in the same directory using the command ln -s
  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 to php.ini using
  3. sudo echo “” >> /etc/php5/apache2/php.ini 
  4. sudo echo “” >> /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 “” > /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
  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
asked Jan 4, 2018 in Education & Reference by Sam (1.6k points) | 1.2k views
1 like 0 dislike
2 answers
1 like 0 dislike
1 answer
0 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 (1.1k points) | 552 views
1 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Jun 27, 2019 in Education & Reference by Simmi (820 points) | 298 views
0 like 0 dislike
1 answer

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

1,313 questions
1,475 answers
4,809 users