If you are facing problems or if you already had headache to install OCI8 and PDO_OCI modules for Oracle as me, here goes a step by step from what has worked for me. I hope that it helps you too.
The steps in this tutorial require that the user has root privileges.
If already have installed the Apache and the PHP, You only have to verify if your computer has all PHP packages listed on step 2.
Step 1 – Install Apache .
Open the terminal and type the follow commands:
sudo apt-get update sudo apt-get install apache2
After install the Apache, try on the browser if the service is running through the URL https:/localhost
Step 2 – Install PHP.
sudo apt-get install php7.0 php7.0-xml php-xml php-common php7.0-cli php7.0-common php7.0-fpm php7.0-json php7.0-opcache php7.0-readline libapache2-mod-php7.0 php-pear php7.0-dev
Step 3- Make the download of the Oracle Client packages, make the download from packages *.rpm > https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
oracle-instantclient11.2-basic-22.214.171.124.0-1.x86_64.rpm oracle-instantclient11.2-sqlplus-126.96.36.199.0-1.x86_64.rpm oracle-instantclient11.2-devel-188.8.131.52.0-1.x86_64.rpm
Step 4 – Install Alien to convert .rpm packages(RedHat family) to .deb packages (Debian family).
$ sudo apt-get install alien
Step 5 – Convert and Install the .rmp files.
$ sudo alien -i oracle-instantclient11.2-basic-184.108.40.206.0-1.x86_64.rpm $ sudo alien -i oracle-instantclient11.2-sqlplus-220.127.116.11.0-1.x86_64.rpm $ sudo alien -i oracle-instantclient11.2-devel-18.104.22.168.0-1.x86_64.rpm
Step 6 – Install the libaio1 library.
$ sudo apt-get install libaio1
Step 7- Create the file oracle.conf in the directory /etc/ld.so.conf.d/
(put into the file, the path from oracle client lib), and after create
the file reload the settings from ldconfig, pay attention to change
the path if your system(PC/OS) is not 64bits (client64).
$ sudo nano /etc/ld.so.conf.d/oracle.conf
paste the path from the lib, in my case it was: /usr/lib/oracle/11.2/client64/lib save the file with the keys CTRL+x
Reload the settings:
$ sudo ldconfig
Step 8 – Export the variable ORACLE_HOME
$ export ORACLE_HOME=/usr/lib/oracle/11.2/client64/
Step 9 – Download the source code from the lib oci8, extract the file’s content, compile and install.
$ pecl download OCI8
------- downloading oci8-2.1.4.tgz ... Starting to download oci8-2.1.4.tgz (191,992 bytes) .........................................done: 191,992 bytes File /home/me/oci8-2.1.4.tgz downloaded oci8-2.1.4.tgz it was the file downloaded --------
$ tar zxvf oci8-2.1.4.tgz #(extracting the file downloaded) $ cd oci8-2.1.4/ $ phpize $ ./configure --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib #(pay attention to the path from oracle lib) $ sudo make install
After the end of compiling and installing, it will show that the file was generated and the path, in my case it was:
---------------------------------------------------------------------- Libraries have been installed in: /home/me/Downloads/oci8-2.1.4/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the 'LD_RUN_PATH' environment variable during linking - use the '-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to '/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Installing shared extensions: /usr/lib/php/20151012/
Step 10 – Enable the generated lib on PHP:
Create the file oci8.ini in the directory from php available modules , in my case it was in the directory /etc/php/7.0/mods-available/ , and after that, create a symbolic link to enable the lib, in my case it was in the directory /etc/php/7.0/apache2/conf.d
$ sudo nano /etc/php/7.0/mods-available/oci8.ini
Paste the lib’s name:
save the file with the keys CTRL+x
$ cd /etc/php/7.0/apache2/conf.d $ sudo ln -s /etc/php/7.0/mods-available/oci8.ini oci8.ini
Step 11 – Check your php version:
$ php -v
PHP 7.0.8-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
Download the source cod from PHP directly from github’s site, download the same version installed in your PC, in my case it was the version 7.0.8 (https://github.com/php/php-src/tree/PHP-7.0.8), case that it is not your version, select the correct version on the menu of branchs and download the zip, this step is for us to get the correct version from the PDO_OCI lib.
Step 12 – Through the command line, extract the downloaded file, compile and install the lib.
$ unzip php-src-PHP-7.0.8.zip #(extracting the downloaded file) $ cd php-src-PHP-7.0.8/ext/pdo_oci/
(this block below is not necessary in new versions[7.0.25 for example], You can go straight to the command -> phpize)
$ nano config.m4
edit the file config.m4 to add the version from oracle 11.2,
find the variable SUPPORTED_LIB_VERS (about line 5)
and add the version number 11.2 in the list of versions,
you have also to look for case $PDO_OCI_VERSION (about line 134)
and add | 11.2 | on the list of versions, save the file with the
$ phpize $ ./configure --with-pdo-oci=instantclient,/usr,11.2 #(pay attention to the version of the oracle lib) $ sudo make install
Step 13 – Enable the pdo_oci lib generated on PHP:
Create the file pdo_oci.ini in the directory from php available modules php and the symbolic link like the step passo 10, you have only to change the lib’s name:
$ sudo nano /etc/php/7.0/mods-available/pdo_oci.ini
paste the lib’s name :
save the file with the keys CTRL+X
$ cd /etc/php/7.0/apache2/conf.d $ sudo ln -s /etc/php/7.0/mods-available/pdo_oci.ini pdo_oci.ini
Step 14 – Restart the apache
$ sudo service apache2 restart
Step 15 – Enable the informations from php, create the file info.php with the function phpinfo() in the html directory from apache; and access through the browser the url https://localhost/info.php and look for libs oci8 and pdo_oci to know if the libs are active.
$ sudo nano /var/www/html/info.php
past this content:
save the file with the keys teclas CTRL+x
When you access the page search for the follow contents, if they are like the images below, you PHP is working properly with the libs oci8 and pdo_oci. After you verify this information, delete the file info.php.