Obsolete PECL/PHP PDO_OCI extension. How to proceed?

Asked

Viewed 3,113 times

2

I need to install the pdo_oci extension of PHP to work with Oracle database, via PDO. However, I checked that the extension available via PECL is obsolete and will no longer be maintained.

From what I understand at this link (I don’t know if I understood correctly), the latest versions of PHP already come with PDO_OCI.

I would like to know how to proceed, as I have found nothing conclusive. I’m using Centos 6.6 with PHP 5.6.

NOTE: I have already installed the basic and devel Rpms of ORACLE Instanclient

Thank you.

2 answers

1

According to the link which is obsolete is the PECL version, from PHP5.3 this extension is standard in PHP and so maybe the PECL repository has been discontinued.

If extensions are not already on the server, recommend installing using command:

yum install php-pdo

Installing OCI8 as a statically compiled extension

Configure PHP to include OCI8 using one of the following lines:

  • If you are using Oracle Instant Client do this:

    ./configure --with-oci8=instantclient,/path/to/instant/client/lib
    
  • If you are using Oracle database or full Oracle Client:

    ./configure --with-oci8=$ORACLE_HOME
    

After setting up, follow the normal build steps, e.g.: make install

Installing OCI8 as a "Shared extension"

The shared configuration option builds OCI8 as a shared library that can be dynamically loaded in PHP. Building a shared extension allows OCI8 to be upgraded easily without affecting the rest of PHP.

  • If you are using the "free » Oracle Instant Client libraries":

    ./configure --with-oci8=shared,instantclient,/path/to/instant/client/lib
    

    If the Instant Client has been installed through ZIP files, create the symbolic links first, for example: ln -s libclntsh.so.12.1 libclntsh.so

  • If you are using an Oracle Instant Client RPM-based installation:

    ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/<version>/client/lib
    

    For example --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client/lib

    Note that initial support for Oracle Instant Client appeared in PHP 4.3.11 and 5.0.4, originally used with --with-oci8-instant-client to configure PHP.

  • If you are using Oracle database or full Oracle Client installation:

    ./configure --with-oci8=shared,$ORACLE_HOME
    

    Verify that the web server user (nobody, www) has access to the libraries, initiating the files and tnsnames.ora (if using) under the directory $ORACLE_HOME. With Oracle 10gR2, you may need to run the utility $ORACLE_HOME/install/changePerm.sh to give access to the directory.

Enable php.ini

To enable "Oracle" in PHP you must open the php.ini file and uncomment the line (remove the ; from the beginning):

;extension=pdo.so
;extension=pdo_oci.so
;extension=pdo_oci8.so

Thus remaining:

extension=pdo.so
extension=pdo_oci.so
extension=pdo_oci8.so

and restart the server.

If the Oracleinstantclient is not "working", may be the wrong version for PHP. Try to download from this link the correct version for your server:

http://www.oracle.com/technetwork/database/features/instant-client/index-100365.html

Note that the PDO extension to PHP is experimental:

This Extension is EXPERIMENTAL. The behaviour of this Extension including the Names of its functions and any other Documentation surrounding this Extension may change without notice in a Future release of PHP. This Extension should be used at your Own risk.

Due to this fact, if any problem arises, try using the functions of oci8.so, see: Connect PHP with Oracle

  • @jflizandro edited the answer, use the command yum install php-pdo

  • Giving a search understood better. Actually not only enable the extension in php.ini, because it does not come in PHP installed via repository. I found that it is necessary to install PHP through the source and compile it with the command ./configure --with-Pdo-oci=instantclient,/usr,. I was able to install it quietly and PDO_OCI enabled right. Only problem is that php pages are being displayed as text. I will perform some VM tests, redoing the whole process.

  • Pdo was already installed, but PDO_OCI does not come in the package, because to compile it is necessary to point the instantclient path, which may vary.

  • @jflizandro I added some details in the installation response, see if help

0


Thank you @guilerme-birth. I was able to install it as follows (remembering that I use Centos 6.6):

Download the PHP

$ wget http://ar2.php.net/get/php-5.6.10.tar.gz/from/this/mirror

Unzip and switch to the unzipped folder

$ tar -xzf php-5.6.10.tar. gz
$ cd php-5.6.10

Run configure command with desired parameters (below my example)

./configure
--prefix=/usr
--sysconfdir=/etc
--localstatedir=/var
--datadir=/usr/share/php
--Mandir=/usr/share/man
--with-config-file-path=/etc
--with-config-file-scan-dir=/etc/php. d
--with-zlib
--enable-bcmath
--with-bz2
--enable-Calendar
--with-gdbm
--with-gmp
--enable-ftp
--with-gettext
--enable-mbstring
--with-readline
--with-apxs2
--with-Pdo-oci=instantclient,/usr,12.1
--enable-dba=Shared
--with-Pdo-mysql --with-mysql-Sock=/var/mysql/mysql.Sock
--with-Pdo-pgsql

OBS: During this step errors may occur due to dependencies that need to be installed before, such as db4 and db4-devel. In my case, I was executing the command, seeing which dependency was giving error. Once identified, install the dependency (always installing also the version devel of each package) and ran again to see the next dependency that was missing. I did this until the command ran error free.

Compiling and installing

$ make && make install

At this point, PHP is already installed.
To make sure, run the following command:

$ php -v

But before we conclude, we need to make some adjustments...

Copy php.ini to the right directory

If you are on a local server
$ cp php.ini-Development /etc/php.ini
If you are on a production server
$ cp php.ini-Production /etc/php.ini

Open apache configuration file for editing

$ vi /etc/httpd/conf/httpd.conf

Add the lines below for Apache to interpret PHP

Addtype application/x-httpd-php . php
Addtype application/x-httpd-php-source . phps

Save and restart Apache

$ service httpd Restart

Ready! By now everything should be working properly!

The disadvantage of this method (at least as far as I noticed) is that whenever you need some module like PDO_MYSQL, PDO_PGSQL etc, you cannot install via package, as it will not work.
To install some, it can be via PECL, except those that are outdated, as the PDO_MYSQL and PDO_OCI, where you must build php again to install these.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.