Skip to content

Instantly share code, notes, and snippets.

@wernerm
Last active January 25, 2020 01:08
Show Gist options
  • Save wernerm/f7d8f63cad2b38913e34c27ebdb47eb1 to your computer and use it in GitHub Desktop.
Save wernerm/f7d8f63cad2b38913e34c27ebdb47eb1 to your computer and use it in GitHub Desktop.
Instructions to install the OCI8 extension for PHP 7 on Ubuntu 18.04 LTS (Bionic)

Installing OCI8 on Ubuntu 18.04

Instructions to install the OCI8 extension for PHP 7.2 on Ubuntu 18.04 LTS (Bionic)

The process has been tested on new servers that have been set up using Virtualmin's installation script.

Setting up Instant Client 19.5

Download the latest version of Instant Client for Linux x86-64 (64-bit). As an example, we will be installing version 19.5.0.0.0 (requires glibc 2.14). You only need to download the Basic Package (ZIP) and the SDK Package (ZIP).

wget -c https://download.oracle.com/otn_software/linux/instantclient/195000/instantclient-basic-linux.x64-19.5.0.0.0dbru.zip
wget -c https://download.oracle.com/otn_software/linux/instantclient/195000/instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip

Extract the downloaded archives to an arbitrary location. We'll use /usr/lib/oracle/.

sudo mkdir -p /usr/lib/oracle/
sudo unzip -d /usr/lib/oracle/ instantclient-basic-linux.x64-19.5.0.0.0dbru.zip
sudo unzip -d /usr/lib/oracle/ instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip

Optionally, you might need to create the symbolic link, if it has not been created by extracting the archives.

sudo ln -s /usr/lib/oracle/instantclient_19_5/libclntsh.so.19.1 /usr/lib/oracle/instantclient_19_5/libclntsh.so

Add the path to the shared Instant Client library files and configure dynamic linker run-time bindings.

sudo sh -c "echo /usr/lib/oracle/instantclient_19_5 > /etc/ld.so.conf.d/oracle.conf"
sudo ldconfig

Setting up the OCI8 PHP extension

Install the required Ubuntu packages. Some may have been installed already.

sudo sudo apt-get install php-dev php-db libaio1

Install the PECL OCI8 package.

sudo pear install pecl/oci8

During installation, you will be prompted for the path to the ORACLE_HOME directory. Enter the path exactly as follows: instantclient\,/usr/lib/oracle/instantclient_19_5

After the build process completes, we need to enable PHP to load the OCI8 extension. That should automatically create a symbolic link, /etc/php/7.2/apache2/conf.d/20-oci8.ini.

sudo echo "extension=oci8.so" > /etc/php/7.2/mods-available/oci8.ini
sudo phpenmod oci8

We now need to restart Apache.

sudo service apache2 restart

Verification

Verify that the OCI8 extension has been installed and that it can be loaded by PHP.

php -m | grep oci8
echo "<?php phpinfo();" | php | grep "OCI8 Support"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment