⬆️ ⬇️

Installing the OCI8 and PDO_OCI Extensions for PHP5

Currently I work for a company that loves to use Oracle projects in PHP projects, sometimes with version 11g.



Most of the developers of this company running under Windows. Over the past month, several of them have decided to join Linux and have set themselves Ubuntu. After a few days after installing the OS itself, the guys were faced with the task of installing PHP drivers for working with Oracle DBMS - OCI8 and PDO_OCI based on Oracle instant client 11.2, which they could not solve on their own.



I did not find a detailed, fully working manual in Russian, by which a newbie in Linux could perform all the manipulations himself. As a result, I had to do a series of the same actions on their machines several times and write a manual, which I present to you.

')

The manual is written for users of Ubuntu Linux, but with some changes suitable for users of most Linux'ov.





Preparing to install



  1. You should be able to execute commands under the administrator;
  2. You must have php5 installed with the following packages (installation command with list):

    sudo apt-get install php5 php5-dev php-pear php5-cli

    sudo pecl install pdo
  3. You must have the libaio1 library installed:

    sudo apt-get install libaio1


Installing Oracle instant client



Download Oracle's Oracle client from the official site http://oracle.com for its processor architecture and OS.

For Linux instant client comes in two versions:



You need to download 2 files:



You can also download:



Create a directory in which the Oracle instant client files will be located (the / opt directory reserved for additional software packages is good for this):

sudo mkdir -p /opt/oracle/



Move the downloaded files to / opt / oracle and go to the destination folder (let's say that you downloaded the “zip archives” to the “downloads” folder of your user):

sudo mv ~/downloads/instantclient-*.zip /opt/oracle/

cd /opt/oracle/




Unzip all downloaded archives:

sudo unzip instantclient-basic-*-*.zip

sudo unzip instantclient-sdk-*-*.zip


If you downloaded SQL * Plus :

sudo unzip instantclient-sqlplus-*-*.zip



As a result, in the / opt / oracle directory was created, for the Oracle instant client 11.2.0.2.0, the instantclient_11_2 directory. Rename this directory to instantclient (if you have another version / directory, change the command) and go to it:

sudo mv instantclient_11_2 instantclient

cd instantclient




Next, you need to create several additional directories and symbolic links for the normal operation of the client (pay attention to the version and if you have another change commands):

sudo ln -s /opt/oracle/instantclient/libclntsh.so.* /opt/oracle/instantclient/libclntsh.so

sudo ln -s /opt/oracle/instantclient/libocci.so.* /opt/oracle/instantclient/libocci.so

sudo ln -s /opt/oracle/instantclient/ /opt/oracle/instantclient/lib



sudo mkdir -p include/oracle/11.2/

cd include/oracle/11.2/

sudo ln -s ../../../sdk/include client

cd -



sudo mkdir -p lib/oracle/11.2/client

cd lib/oracle/11.2/client

sudo ln -s ../../../ lib

cd -




Create a configuration file in which the directory will be specified to search for the Oracle instant client libraries, and include it:

echo /opt/oracle/instantclient/ | sudo tee -a /etc/ld.so.conf.d/oracle.conf

sudo ldconfig




Since there is no / usr / include / php directory in Ubuntu, and the client is still looking for it, we will create a symbolic link to its php5 equivalent:

sudo ln -s /usr/include/php5 /usr/include/php



Install OCI8



After all our manipulations, the oci8 extension is remarkably installed using the pecl command :

sudo pecl install oci8

we are asked to enter the path to the Oracle instant client, to which we must respond:

instantclient,/opt/oracle/instantclient



Create an extension connection file:

echo "; configuration for php oci8 module" | sudo tee /etc/php5/conf.d/oci8.ini

echo extension=oci8.so | sudo tee -a /etc/php5/conf.d/oci8.ini




Set PDO_OCI



To install PDO_OCI, we first need to download it from the pear repository .

Update the pear package list:

sudo pecl channel-update pear.php.net



Download and place the archive in the temporary directory:

sudo mkdir -p /tmp/pear/download/

cd /tmp/pear/download/

sudo pecl download pdo_oci




Extract the contents of the archive and go to it:

sudo tar xvf PDO_OCI*.tgz

cd PDO_OCI*




Here we need to adjust the file config.m4, since it does not contain data about our version of Oracle instant client, the latest changes are dated 2005. Run your favorite editor and make changes marked with "+" (note the version and if you have another one, change the lines):

sudo vim config.m4



The following is a diff of two files:

***************

*** 7,12 ****

--- 7,14 ----

if test -s "$PDO_OCI_DIR/orainst/unix.rgs"; then

PDO_OCI_VERSION=`grep '"ocommon"' $PDO_OCI_DIR/orainst/unix.rgs | sed 's/[ ][ ]*/:/g' | cut -d: -f 6 | cut -c 2-4`

test -z "$PDO_OCI_VERSION" && PDO_OCI_VERSION=7.3

+ elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then

+ PDO_OCI_VERSION=11.2

elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.10.1; then

PDO_OCI_VERSION=10.1

elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.9.0; then

***************

*** 119,124 ****

--- 121,129 ----

10.2)

PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)

;;

+ 11.2)

+ PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)

+ ;;

*)

AC_MSG_ERROR(Unsupported Oracle version! $PDO_OCI_VERSION)

;;

***************



Preparing the environment for php extension using the phpize command (pay attention to the version, if you change it for another):

sudo phpize



Configure the package installer and install the package (note the version, if you have another change):

sudo ./configure --with-pdo-oci=instantclient,/opt/oracle/instantclient/,11.2

sudo make

sudo make install





Create a connection file for it:

echo "; configuration for php PDO_OCI module" | sudo tee /etc/php5/conf.d/pdo_oci.ini

echo extension=pdo_oci.so | sudo tee -a /etc/php5/conf.d/pdo_oci.ini




Summing up



Restart apache and check for installed extensions:

sudo /etc/init.d/apache2 restart

php -m




Conclusion



The manual is based on this post , which has been slightly reworked - bugs fixed and additions made.



I hope the article will be useful not only to my colleagues.

Source: https://habr.com/ru/post/116474/



All Articles