sudo apt-get install php7.0 php7.0-xml 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
sudo apt-get install alien
sudo apt-get install unzip

Step 5 – Convert and Install the .rmp files.

Download Oracle Instantclient from http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html.Use Alien command to convert all RMP files, the rpm packages will be extracted into /usr/lib/oracle which is the Oracle instantclient library and ORACLE_HOME location. Please note instead of RMP file, we will use the zip file for Oracle Instantclient SDK file.

$ sudo alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
$ sudo alien -i oracle-instantclient12.1-devel-12.1.0.2.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/

$ sudo nano /etc/ld.so.conf.d/oracle.conf
$ sudo echo /usr/lib/oracle/12.1/client64/lib>/etc/ld.so.conf.d/oracle.conf
$ sudo ldconfig

Step 8 – Export the variable ORACLE_HOME

$ export ORACLE_HOME=/usr/lib/oracle/12.1/client64/

Step 9 – Download and compile the lib oci8

$ pecl download OCI8
$ tar zxvf oci8-2.1.8.tgz #(extracting the file downloaded)
$ cd oci8-2.1.8/
$ phpize
$ ./configure --with-oci8=instantclient,/usr/lib/oracle/12.1/client64/lib #(pay attention to the path from oracle lib)
$ sudo make install

Step 10 – Enable the generated OCI8 lib on PHP

$ sudo nano /etc/php/7.0/mods-available/oci8.ini
$ sudo echo extension=oci8.so>/etc/php/7.0/mods-available/oci8.ini
$ cd /etc/php/7.0/apache2/conf.d
$ sudo ln -s /etc/php/7.0/mods-available/oci8.ini oci8.ini

Step 11 – Download the source code from PHP repository

$ sudo php -v
PHP 7.0.25-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.25-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

Execute php -v and remember the installed PHP version returned. Download the matched version from https://github.com/php/php-src/tree/PHP-7.0.25

Step 12 – Compile the PDO_OCI extension

$ unzip php-src-PHP-7.0.25.zip
$ cd php-src-PHP-7.0.25/ext/pdo_oci/
$ ./configure --with-pdo-oci=instantclient,/usr,12.1
$ sudo make install

Step 13 – Enable the pdo_oci lib generated on PHP

$ sudo nano /etc/php/7.0/mods-available/pdo_oci.ini
$ sudo echo extension=pdo_oci.so>/etc/php/7.0/mods-available/pdo_oci.ini
$ 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

 

 

检查

php –ri oci8 可以检查 oci8 扩展是否安装成功,也可以检查当前的 oci8 连接数

OCI8 Support => enabled
OCI8 DTrace Support => disabled
OCI8 Version => 2.0.7
Revision => $Id: f04114d4d67cffea4cdc2ed3b7f0229c2caa5016 $
Oracle Run-time Client Library Version => 12.1.0.1.0
Oracle Compile-time Instant Client Version => 12.1

Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 100 => 100
oci8.old_oci_close_semantics => Off => Off
oci8.connection_class => no value => no value
oci8.events => Off => Off

Statistics =>
Active Persistent Connections => 0
Active Connections => 0

纠错

$ php -ri oci8
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20121212/oci8.so’ – libaio.so.1: cannot open shared object file: No such file or directory in Unknown on line 0

上述错误,由事先未安装 libpiao-dev 引起