Install OCI8 on Ubuntu Linux 16.04 with PHP7.0 and PHP7.1

How to install OCI8 on Ubuntu Linux with PHP7.0 and PHP7.1

Its very easy to install OCI8 on Ubuntu Linux and you can easily access you database on web by using this simple steps.


First refer to below link and install Oracle Instant Client on Ubuntu along with Oracle Libraries integration and SDK fix and also to set Oracle_Home.

Install Oracle Instant Client on Ubuntu (Linux)


After doing the exercise as mentioned above, now we have installed all the compulsory packages. now run below command to install some more essential packages for OCI8.

sudo apt-get install php-dev php-pear build-essential libaio1

after executing above command now we are going to install OCI8

sudo pecl install oci8

when you execute the above command then it will prompt for instantclient path, then enter follwing

instantclinet,/usr/lib/oracle/<version>/client64/lib – (for x86-x64bit)

example:- instantclient,/usr/lib/oracle/12.2/clinet64/lib (for x86-x64bit)

exampe:- instantclient,/usr/lib/oracle/12.2/clinet/lib (for x86)


Now We need to load OCI8 extension in PHP, so execute the below command.

echo “extension =” >> /etc/php/7.0/cli/php.ini


echo “extension =” >> /etc/php/7.1/cli/php.ini

this command will add “extension =” in php.ini file so that PHP will start getting data from Oracle.


Now we need to check that OCI8 Extension has been enabled or not, so check it with below command.

php -m | grep ‘oci8’

if it returns oci8, then its ok


Now simply restart appche2 service and

sudo service apache2 restart.


Copy Below code and save it to oracle.php and run on apache2 server


// Connects to the XE service (i.e. database) on the “localhost” machine
$conn = oci_connect(‘username’, ‘password’, ‘ip or localhost/SID’);
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e[‘message’], ENT_QUOTES), E_USER_ERROR);

$stid = oci_parse($conn, ‘SELECT * FROM  table_name’);

echo “<table border=’1′>\n”;
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo “<tr>\n”;
foreach ($row as $item) {
echo ” <td>” . ($item !== null ? htmlentities($item, ENT_QUOTES) : “&nbsp;”) . “</td>\n”;
echo “</tr>\n”;
echo “</table>\n”;



Leave a Reply

Your email address will not be published. Required fields are marked *