Skip to content

Instantly share code, notes, and snippets.

@vicsimental
Last active August 30, 2023 12:12
Show Gist options
  • Save vicsimental/b4968ea72a57def8247fcdb0c51efe28 to your computer and use it in GitHub Desktop.
Save vicsimental/b4968ea72a57def8247fcdb0c51efe28 to your computer and use it in GitHub Desktop.
How to install OCI8 on Debian 10 Buster / Ubuntu 18.04 LTS / Ubuntu 16.04 and PHP 7.3

How to install OCI8 on Debian 10 Buster / Ubuntu 18.04 LTS / Ubuntu 16.04 and PHP 7.3

Source: http://www.syahzul.com/2016/04/06/how-to-install-oci8-on-ubuntu-14-04-and-php-5-6/

Install Oracle Instant Client and SDK

Step 1

Download the Oracle Instant Client and SDK from Oracle website. (Need to login in Oracle page)

http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

Files: instantclient-basic-linux.x64-12.1.0.2.0.zip and instantclient-sdk-linux.x64-12.1.0.2.0.zip.

Step 2

Create a new folder to store Oracle Instant Client zip files on your server.

Upload the Instant Clients files inside this folder.

mkdir /opt/oracle

Step 3

Now we need to extract the files.

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

Step 4

Next, we need to create a symlink to Instant Client files.

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 5

Add the folder to our ldconfig.

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

Step 6

Update the Dynamic Linker Run-Time Bindings

ldconfig

Done. Now we can proceed to the next part.

Install Additional Packages

To install the OCI8 extension, we need to install some additional package on our server.

Step 1

Run these command:

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

Step 2

Once installed, we need to get the OCI8 file.

pecl install oci8

When you are prompted for the Instant Client location, enter the following:

instantclient,/opt/oracle/instantclient_12_1

Step 3

We need to tell PHP to load the OCI8 extension.

echo "extension = oci8.so" >> /etc/php/7.3/fpm/php.ini
echo "extension = oci8.so" >> /etc/php/7.3/cli/php.ini

Step 4

Check if the extension is enabled.

php -m | grep 'oci8'

If returns oci8, its works!

Step 5

Restart the PHP-FPM

service php7.3-fpm restart

Now you can connect to Oracle DBMS from your PHP applications.

@c8001221
Copy link

At step 5, it should be

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

@freehussain
Copy link

yes you are right it should end woth .conf

@tzitzimime
Copy link

In my case for Debian GNU/Linux 11 (bullseye) with php-7.4

Download
Files: instantclient-basic-linux.x64-12.1.0.2.0.zip and instantclient-sdk-linux.x64-12.1.0.2.0.zip
mkdir /opt/oracle
cd /opt/oracle
unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip
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
echo /opt/oracle/instantclient_12_1 > /etc/ld.so.conf.d/oracle-instantclient.conf
ldconfig
apt-get install php-dev php-pear build-essential libaio1 systemtap-sdt-dev
pecl install oci8-2.2.0
instantclient,/opt/oracle/instantclient_12_1
echo "extension = oci8.so" >> /etc/php/7.4/apache2/php.ini
sudo systemctl restart apache2.service

@hussam-qasem
Copy link

Pick your desired version from Oracle's Instant Client website. For example, select the OL7 RPM x86 packages, and run the following as root:

curl -LO https://download.oracle.com/otn_software/linux/instantclient/2111000/oracle-instantclient-basic-21.11.0.0.0-1.x86_64.rpm
curl -LO https://download.oracle.com/otn_software/linux/instantclient/2111000/oracle-instantclient-sqlplus-21.11.0.0.0-1.x86_64.rpm
curl -LO https://download.oracle.com/otn_software/linux/instantclient/2111000/oracle-instantclient-devel-21.11.0.0.0-1.x86_64.rpm

apt-get update

apt-get install -y --no-install-recommends fakeroot alien libaio1

fakeroot alien --scripts --install oracle-instantclient-*.rpm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment