Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save syahzul/8f29a34a45c62fc577f7964ba123d4ba to your computer and use it in GitHub Desktop.
Save syahzul/8f29a34a45c62fc577f7964ba123d4ba to your computer and use it in GitHub Desktop.
Install PHP OCI8 on RunCloud Ubuntu 20.04

How To Install OCI8 on RunCloud Ubuntu 20.04

Step 1

Download the Oracle Instant Client and SDK from Oracle website.

https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html

Files:

  • instantclient-basic-linux.x64-19.9.0.0.0dbru.zip
  • instantclient-sdk-linux.x64-19.9.0.0.0dbru.zip.

Step 2

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

sudo mkdir /opt/oracle

Upload the downloaded files to this folder. Now we need to extract the files.

cd /opt/oracle

unzip instantclient-basic-linux.x64-19.9.0.1.0.zip
unzip instantclient-sdk-linux.x64-19.9.0.1.0.zip

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

ln -s /opt/oracle/instantclient_19_9/libclntsh.so.19.1 /opt/oracle/instantclient_19_9/libclntsh.so
ln -s /opt/oracle/instantclient_19_9/libocci.so.19.1 /opt/oracle/instantclient_19_9/libocci.so

Step 4

Add the folder to our ldconfig.

sudo -s
echo /opt/oracle/instantclient_19_9 > /etc/ld.so.conf.d/oracle-instantclient.conf

Run the command below to update the Dynamic Linker Run-Time Bindings

ldconfig

Step 5

Download oci8-2.2.0.tgz from official PHP website. Make sure not to download oci8-3.0.0.tgz since it's for PHP8.

https://pecl.php.net/get/oci8-2.2.0.tgz

Step 6

Extract the file.

tar -zxf oci8-2.2.0.tgz
cd oci8-2.2.0

Step 7

We need autoconf installed before we can proceed.

apt install autoconf

Step 8

Install using PHPIZE

make clean

/RunCloud/Packages/php74rc/bin/phpize --clean

/RunCloud/Packages/php74rc/bin/phpize

./configure --with-oci8=shared,instantclient,/opt/oracle/instantclient_19_9 --with-php-config=/RunCloud/Packages/php74rc/bin/php-config

make install

Step 9

Next, we need to create ini files for PHP.

echo "extension = oci8.so" >> /etc/php72rc/conf.d/oci8.ini
echo "extension = oci8.so" >> /etc/php73rc/conf.d/oci8.ini
echo "extension = oci8.so" >> /etc/php74rc/conf.d/oci8.ini

Don't forget to restart PHP-FPM.

systemctl restart php74rc-fpm.service
systemctl restart php73rc-fpm.service
systemctl restart php72rc-fpm.service

Test OCI8

From your Terminal, check if the module is loaded:

php -i | grep 'oci8'

If returns oci8, its works!

Or, create a PHP file and add the code below:

<?php

if (function_exists('oci_connect')) {
    echo 'OCI8 is working!';
}
else {
    echo 'Whoopss...not working!';
}

Test it on your web browser.

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