In case we would like to use Oracle database in our PHP application. We need
to install OCI8 extension. However, it can not be done with simple command like
apt install php-oci8, but we need to download Oracle Instant Client and SDK first.
Install Oracle Instant Client and SDK
First we need to download Instant Cliend and SDk from (Oracle website).
You also need to create an account to be able to download the file. Then look for
After successful download of these files we need to create a folder in
/opt and move the files there.
Then we can extrat the files.
cd /opt/oracle unzip instantclient-basic-linux.x64-[verze].zip unzip instantclient-sdk-linux.x64-[verze].zip
Next, we need to symlik the
.so files. Keep in mind that your version of Instant Client
and SDK could be different than the on in this tutorial, so please check names of your files.
ln -s /opt/oracle/instantclient_19_5/libclntsh.so.19.5 /opt/oracle/instantclient_19_5/libclntsh.so ln -s /opt/oracle/instantclient_19_5/libocci.so.19.5 /opt/oracle/instantclient_19_5/libocci.so
Now lets add the folder to the ldconfig’s config folder. Again check folder name.
echo /opt/oracle/instantclient_19_5 > /etc/ld.so.conf.d/oracle-instantclient.conf
And finally update the dynamic linker runtime bindings.
Add extension to PHP
To install the OCI8 extension, we need to get some additional packages. So, run following command to get necessary packages:
apt install php-dev php-pear build-essential libaio1
Then install the oci8 extension via PECL.
echo "instantclient,/opt/oracle/instantclient_12_2" | pecl install oci8
Now we need to tell PHP to load the OCI8 extension. In this tutorial I have
installed PHP version 7.3, your version could be different. To get to know which
version of PHP is used, please run command
echo "extension=oci8.so" >> /etc/php/7.3/mods-available/oci8.ini ln -s /etc/php/7.3/mods-available/oci8.ini /etc/php/7.3/cli/conf.d/20-oci8.ini ln -s /etc/php/7.3/mods-available/oci8.ini /etc/php/7.3/fpm/conf.d/20-oci8.ini
Next we need to check if the extension is enabled.
php -m | grep oci8 php-fpm7.3 -m | grep oci8
If you see
oci8, you are almost done! Just restart PHP-FPM service.
service php7.1-fpm restart