在Ubuntu中的PHP 5.6中的Oracle数据库连接

I'm trying to create an OCI8 connection using php5.6 in ubuntu. I'm following this link for the tutorial.

But I'm getting an error after running the command pecl install oci8-2.0.10. Here is the screenshot of the error.

Assuming you are using the system PHP:

  • Install the 'php-dev' or similar package to get the PHP header files

  • Use 'pecl install oci8-2.0.12', since 2.0.12 is the latest version for PHP 5.6

For php5.6

Note please that this works, but be aware that could be are some unnecesary steps or improvements, I just done this once and had no time to polish it.

This is for a manual installation without pecl command because it seems that is your problem

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

In "Version 12.2.0.1.0" Section

  • "Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications"

Download instantclient-basic-linux.x64-12.2.0.1.0.zip

  • "Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client"

Download instantclient-sdk-linux.x64-12.2.0.1.0.zip

2- Unzip instantclient-basic-linux.x64-12.2.0.1.0.zip and copy to the dir you want i.e :

cp -R instantclient_12_2/ /usr/lib/

3- Unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip and copy sdk headers to the dir where you have copied instanclient

cp -R ./instantclient_12_2/sdk /usr/lib/instantclient_12_2/

4- Make symlinks :

cd /usr/lib/instantclient_12_2
ln -s libocci.so.12.1 libocci.so
ln -s libclntsh.so.12.1 libclntsh.so

5- Configure lib path :

  • edit /etc/environment file and insert at the end : LD_LIBRARY_PATH="/usr/lib/instantclient_12_2"
  • edit ~/.bashrc file and insert at the end : export
    LD_LIBRARY_PATH=/usr/lib/instantclient_12_2

6- Install dev packages :

apt install -y php5.6-dev

7- Go to https://pecl.php.net/package/oci8

Download https://pecl.php.net/get/oci8-2.0.12.tgz

8- untar it :

tar -zxf oci8-1.4.10.tgz

9- compile and config :

cd oci8-1.4.10
phpize
./configure -with-oci8=shared,instantclient,/usr/lib/instantclient_12_2/
make install

10- enable extension (in this case in fpm)

edit /etc/php/5.6/fpm/php.ini file and insert at the end > extension=oci8.so

11- restart service :

service php5.6-fpm restart

Have fun.

PS: The most helping site that I found while looking for info when I was doing this was http://www.phptutorial.info/?oci8.installation , has explanations to install with/out pecl, manually, etc.