This tutorial only tested with Ubuntu Server 20.04 configured by RunCloud.
Visit Oracle Instant Client website and download the following files:
- instantclient-basic-linux.x64-19.9.0.0.0dbru.zip
- instantclient-sdk-linux.x64-19.9.0.0.0dbru.zip
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
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
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
Extract the downloaded file.
tar -zxf oci8-2.2.0.tgz
cd oci8-2.2.0
We need autoconf
installed before we can proceed.
apt install autoconf
Install using phpize
provided by RunCloud.
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
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
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.