Main menu
WalkswithMePHPHow to install OCI8 extension for PHP Oracle development

How to install OCI8 extension for PHP Oracle development

How to install OCI8 extension for PHP Oracle development  ? you may think is quite easy and just one step mentioned in the php.net those are just in dreams or some luck. otherwise you have to drill down to all the steps to get it works.

Recently I had a PHP Oracle project , I used Laravel for this project and used one of the best OCI8 adapter available for Laravel. the projects now looks good, but before getting to that level we have to think about basic requirement of the PHP OCI8 extension in our development system.

My system and tools are below.

  • Linux Mint Debian Edition
  • Apache Server
  • PHP 5.6+

If you’re installing this extension on your server make sure you have Sudo privilege most of the command required admin privilege .

Step 1

Oracle Instant client and SDK Installation

First you have to install Oracle instant client and sdk for your distro. you can check this page and find what package is suitable for your server or development edition. In my case its Instant Client for Linux x86-64 and I just downloaded the following packages.

Step 2

Now we need to create a directory for Oracle instant client , I’m just creating it in the following path it may need Sudo privilege


mkdir /opt/oracle

Now just copy the downloaded files to this path and unzip it.


cd /otp/oracle
unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip

after the extraction you have a folder called instantclient_12_1 you need to create symlink for this path.

Step 3

Creating symlink for Oracle instant client


ln -s /opt/oracle/instantclient_12_1/libclntsh.so.12.1 /opt/oracle/instantclient_12_1/libclntsh.so
ln -s /opt/oracle/instantclient_12_1/libocci.so.12.1 /opt/oracle/instantclient_12_1/libocci.so
Step 4

Now we have to configure dynamic linker run time bindings


echo /opt/oracle/instantclient_12_1 > /etc/ld.so.conf.d/oracle-instantclient
Step 5

Now we have to Update the Dynamic Linker Run-Time Bindings


ldconfig
Step 6

Install Additional packages required for Oracle Instant Client.


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

Once the above command completed now we are good to go with pecl installation of OCI8


pecl install oci8-2.0.10

The above command running time it will ask for the Oracle instant client library path so you have to enter the correct path so in my case it should be


instantclient,/opt/oracle/instantclient_12_1
Step 7

Now we have to add the OCI8 extension to our php.ini files, the files path may different in your case for my case it as follows.


echo "extension = oci8.so" >> /etc/php5/apache2/php.ini
echo "extension = oci8.so" >> /etc/php5/cli/php.ini

If you’re not sure about the php.ini file path you can use the Basic linux command as follows.


locate php.ini

it will return all the path available for php.ini files.

Step 8

Now we just need to restart our Apache server.


sudo service apache2 restart

Now you’re able to connect PHP to Oracle DB. In my situation my development machine is not installed with Oracle its in a remote machine So I’m using host and its db details in my Laravel PHP application.

Oracle SQL Developer Tool for Oracle DB UI management

Yes here I’m using SQL developer tool for managing my remote Oracle DB’s. you can just download it from here. I just downloaded the Other platform package from this list bcoz for debian edition no separate package available. just extract the package to a folder and run the .sh file in it.

Mysql to Oracle DB migration

How to migrate a Mysql DB to Oracle DB ? the easiest way is to connect your current Mysql DB with Oracle SQL Developer and export or Copy it to Oracle DB. so in that case you need an extra tool to open Mysql DB inside Oracle Developer tool. You can download the JDBC Driver for MySQL (Connector/J)

Now just extract it to a folder it have a .jar file now just follows the steps.

  • Open SQL developer tool.
  • Tools -> Preferences -> Database -> Third party JDBC drivers
  • Add new and choose our Mysql connector jar file.
  • Apply and ok, then just close and open the Developer tool.
SQL Developer mysql Driver

SQL Developer mysql Driver

Now you will be able to see new tab near the connector as Mysql. just set your Mysql DB details and connect once you connect you will be able copy or migrate the DB to Oracle.

Happy reading 🙂 🙂 🙂 .

 

One thought on “How to install OCI8 extension for PHP Oracle development

  1. Hello Sir,

    I have one project which I am working on
    Can you guide me on how can we use Laravel + Eloquent + Triggers and Stored Procedures (not just create trigger and proc through up and down default functions in models)

    will you please guide how to use triggers, pass trigger parameter values and return the results back to Laravel

    any step by step guide, video with an example would be greatly appreciated.
    Thanks
    Sandeep

Leave a Reply

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

 

FacebookTwitterGoogle+RSS