Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codymoorhouse/21441cb6c15135e13fd819bd202cdcfe to your computer and use it in GitHub Desktop.
Save codymoorhouse/21441cb6c15135e13fd819bd202cdcfe to your computer and use it in GitHub Desktop.
How to install OCI8 on Ubuntu 17.10 and PHP 7.1

How to install OCI8 on Ubuntu 17.10 and PHP 7.1

This guide refers to Instantclient Version 12.2.0.1.0

Install Oracle Instant Client and SDK

Step 1

Download the latest Oracle Instant Client and SDK from the Oracle website (Yeah, fuck you Oracle, you need to create an account to download the files).

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

Look for instantclient-basic-linux.x64-12.2.0.1.0.zip and instantclient-sdk-linux.x64-12.2.0.1.0.zip.

Step 2

Create a new folder to store the Oracle Instant Client files on your machine.

mkdir /opt/oracle

And move your files to /opt/oracle.

Step 3

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 4

Next, we need to symlink the .so files.

ln -s /opt/oracle/instantclient_12_2/libclntsh.so.12.2 /opt/oracle/instantclient_12_2/libclntsh.so
ln -s /opt/oracle/instantclient_12_2/libocci.so.12.2 /opt/oracle/instantclient_12_2/libocci.so

Step 5

Now lets add the folder to the ldconfig's config folder.

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

And update the dynamic linker runtime bindings.

ldconfig

Great! We're almost there!

Add the extension to PHP

To install the OCI8 extension, we need to get some additional packages.

Step 1

Run these commands to install the necessary packages:

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

Step 2

Install the oci8 extension via PECL.

pecl install oci8

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

instantclient,/opt/oracle/instantclient_12_2

Step 3

We now can tell PHP to load the OCI8 extension.

echo "extension=oci8.so" >> /etc/php/7.1/mods-available/oci8.ini

ln -s /etc/php/7.1/mods-available/oci8.ini /etc/php/7.1/cli/conf.d/20-oci8.ini

ln -s /etc/php/7.1/mods-available/oci8.ini /etc/php/7.1/fpm/conf.d/20-oci8.ini

Step 4

Check if the extension is enabled.

php -m | grep oci8
php-fpm7.1 -m | grep oci8

If you see oci8, you're almost done!

Step 5

Restart PHP-FPM.

service php7.1-fpm restart

Finished! Well done! Thanks for pulling through with this tedious procedure!

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