Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save syahzul/41fb57bd5aa3ba9b2eb00b264d53843c to your computer and use it in GitHub Desktop.
Save syahzul/41fb57bd5aa3ba9b2eb00b264d53843c to your computer and use it in GitHub Desktop.
How to install OCI8 on Linux Mint 19.2 and PHP 7.3 (Instant Client 19.5)

How to install OCI8 on Linux Mint 19.2 and PHP 7.3

Sources:

Upgrade or install PHP 7.3

Step 1

Add Ondřej Surý PHP PPA

sudo add-apt-repository ppa:ondrej/php

apt update && apt upgrade

apt install php7.3-curl php7.3-gd php7.3-mysql php7.3-mbstring php7.3-cli php7.3-xml php7.3-zip

Install Oracle Instant Client and SDK

Step 2

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.5.0.0.0dbru.zip and instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip.

Step 3

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

Upload the Instant Clients files inside this folder.

sudo mkdir /opt/oracle

Step 4

Now we need to extract the files.

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

Step 5

Add the folder to our ldconfig.

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

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 install php-dev php-pear build-essential libaio1

Step 2

Once installed, we need to get the OCI8 file. But, before that we need to update PECL channel.

pecl channel-update pecl.php.net

Then.

pecl install oci8

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

instantclient,/opt/oracle/instantclient_19_5

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
echo "extension = oci8.so" >> /etc/php/7.3/apache2/php.ini

We also need to add on apache those environment variables.

echo "export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_5" >> /etc/apache2/envvars
echo "export ORACLE_HOME=/opt/oracle/instantclient_19_5" >> /etc/apache2/envvars
echo "LD_LIBRARY_PATH=/opt/oracle/instantclient_19_5:$LD_LIBRARY_PATH" >> /etc/environment

Step 4

Refresh the server. If you are accessing through SSH, then

exit

or

sudo shutdown -r now

Check if the extension is enabled.

php -m | grep 'oci8'

If returns oci8, its works!

Step 5

Restart the PHP-FPM

systemctl restart php7.3-fpm.service

Test it out!

Create a file containing the following codes.

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

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

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