Debian Jessie + PHP + OCI8

Comment installer le connecteur OCI8 pour php5 sur Debian (8.x) aka Jessie .

  • Debian 8.6 x86-64
  • Oracle Instant Client 11.2

Préparation :

apt-get install build-essential php5-dev php-pear libaio1 unzip

Télécharger l’Oracle Instant Client  (basic et sdk ) depuis le site d’Oracle :

# cp *.zip /usr/local/lib/
# cd /usr/local/lib/
# unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip 
Archive:  instantclient-sdk-linux.x64-11.2.0.4.0.zip
   creating: instantclient_11_2/sdk/
   creating: instantclient_11_2/sdk/include/
  inflating: instantclient_11_2/sdk/include/occi.h  
  inflating: instantclient_11_2/sdk/include/occiCommon.h  
  inflating: instantclient_11_2/sdk/include/occiControl.h  
  inflating: instantclient_11_2/sdk/include/occiData.h  
  inflating: instantclient_11_2/sdk/include/occiObjects.h  
  inflating: instantclient_11_2/sdk/include/occiAQ.h  
  inflating: instantclient_11_2/sdk/include/oci.h  
  inflating: instantclient_11_2/sdk/include/oci1.h  
  inflating: instantclient_11_2/sdk/include/oci8dp.h  
  inflating: instantclient_11_2/sdk/include/ociap.h  
  inflating: instantclient_11_2/sdk/include/ociapr.h  
  inflating: instantclient_11_2/sdk/include/ocidef.h  
  inflating: instantclient_11_2/sdk/include/ocidem.h  
  inflating: instantclient_11_2/sdk/include/ocidfn.h  
  inflating: instantclient_11_2/sdk/include/ociextp.h  
  inflating: instantclient_11_2/sdk/include/ocikpr.h  
  inflating: instantclient_11_2/sdk/include/ocixmldb.h  
  inflating: instantclient_11_2/sdk/include/ocixstream.h  
  inflating: instantclient_11_2/sdk/include/odci.h  
  inflating: instantclient_11_2/sdk/include/oratypes.h  
  inflating: instantclient_11_2/sdk/include/ori.h  
  inflating: instantclient_11_2/sdk/include/orid.h  
  inflating: instantclient_11_2/sdk/include/orl.h  
  inflating: instantclient_11_2/sdk/include/oro.h  
  inflating: instantclient_11_2/sdk/include/ort.h  
  inflating: instantclient_11_2/sdk/include/xa.h  
  inflating: instantclient_11_2/sdk/include/nzt.h  
  inflating: instantclient_11_2/sdk/include/nzerror.h  
  inflating: instantclient_11_2/sdk/include/ldap.h  
   creating: instantclient_11_2/sdk/demo/
  inflating: instantclient_11_2/sdk/demo/demo.mk  
  inflating: instantclient_11_2/sdk/demo/cdemo81.c  
  inflating: instantclient_11_2/sdk/demo/occidemo.sql  
  inflating: instantclient_11_2/sdk/demo/occidemod.sql  
  inflating: instantclient_11_2/sdk/demo/occidml.cpp  
  inflating: instantclient_11_2/sdk/demo/occiobj.cpp  
  inflating: instantclient_11_2/sdk/demo/occiobj.typ  
  inflating: instantclient_11_2/sdk/SDK_README  
 extracting: instantclient_11_2/sdk/ottclasses.zip  
  inflating: instantclient_11_2/sdk/ott  
# unzip instantclient-basic-linux.x64-11.2.0.4.0.zip 
Archive:  instantclient-basic-linux.x64-11.2.0.4.0.zip
  inflating: instantclient_11_2/BASIC_README  
  inflating: instantclient_11_2/adrci  
  inflating: instantclient_11_2/genezi  
  inflating: instantclient_11_2/libclntsh.so.11.1  
  inflating: instantclient_11_2/libnnz11.so  
  inflating: instantclient_11_2/libocci.so.11.1  
  inflating: instantclient_11_2/libociei.so  
  inflating: instantclient_11_2/libocijdbc11.so  
  inflating: instantclient_11_2/ojdbc5.jar  
  inflating: instantclient_11_2/ojdbc6.jar  
  inflating: instantclient_11_2/uidrvci  
  inflating: instantclient_11_2/xstreams.jar  
# cd instantclient_11_2/
# ls -al
total 183536
drwxr-sr-x 3 root staff      4096 Nov 22 16:30 .
drwxrwsr-x 5 root staff      4096 Nov 22 16:30 ..
-rwxrwxr-x 1 root staff     25420 Aug 24  2013 adrci
-rw-rw-r-- 1 root staff       439 Aug 24  2013 BASIC_README
-rwxrwxr-x 1 root staff     47860 Aug 24  2013 genezi
-rwxrwxr-x 1 root staff  53865194 Aug 24  2013 libclntsh.so.11.1
-r-xr-xr-x 1 root staff   7996693 Aug 24  2013 libnnz11.so
-rwxrwxr-x 1 root staff   1973074 Aug 24  2013 libocci.so.11.1
-rwxrwxr-x 1 root staff 118738042 Aug 24  2013 libociei.so
-r-xr-xr-x 1 root staff    164942 Aug 24  2013 libocijdbc11.so
-r--r--r-- 1 root staff   2091135 Aug 24  2013 ojdbc5.jar
-r--r--r-- 1 root staff   2739616 Aug 24  2013 ojdbc6.jar
drwxrwsr-x 4 root staff      4096 Aug 24  2013 sdk
-rwxrwxr-x 1 root staff    192365 Aug 24  2013 uidrvci
-rw-rw-r-- 1 root staff     66779 Aug 24  2013 xstreams.jar
# ln -s libclntsh.so.11.1 libclntsh.so

D’apres le site de PECL, nous devons installer la version 1.4.x d’oci8 si on utilise PHP5 . Nous utiliserons le paramètre :

instantclient,/usr/local/lib/instantclient_11_2
# pecl install oci8-1.4.10
downloading oci8-1.4.10.tgz ...
Starting to download oci8-1.4.10.tgz (169,248 bytes)
.....done: 169,248 bytes
10 source files, building
running: phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
Please provide the path to the ORACLE_HOME directory. Use 'instantclient,/path/to/instant/client/lib' if you're compiling with Oracle Instant Client [autodetect] : instantclient,/usr/local/lib/instantclient_11_2
building in /tmp/pear/temp/pear-build-rootutoK4c/oci8-1.4.10
running: /tmp/pear/temp/oci8/configure --with-oci8=instantclient,/usr/local/lib/instantclient_11_2
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
[...]
Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10" install
Installing shared extensions:     /tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10/usr/lib/php5/20131226/
running: find "/tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10" | xargs ls -dils
262997   4 drwxr-xr-x 3 root root   4096 Nov 22 16:39 /tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10
263027   4 drwxr-xr-x 3 root root   4096 Nov 22 16:39 /tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10/usr
263028   4 drwxr-xr-x 3 root root   4096 Nov 22 16:39 /tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10/usr/lib
263029   4 drwxr-xr-x 3 root root   4096 Nov 22 16:39 /tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10/usr/lib/php5
263030   4 drwxr-xr-x 2 root root   4096 Nov 22 16:39 /tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10/usr/lib/php5/20131226
263026 504 -rwxr-xr-x 1 root root 512928 Nov 22 16:39 /tmp/pear/temp/pear-build-rootutoK4c/install-oci8-1.4.10/usr/lib/php5/20131226/oci8.so

Build process completed successfully
Installing '/usr/lib/php5/20131226/oci8.so'
install ok: channel://pecl.php.net/oci8-1.4.10
configuration option "php_ini" is not set to php.ini location
You should add "extension=oci8.so" to php.ini

Nous pouvons activer l’extension dans PHP5 :

echo "extension=oci8.so"  > /etc/php5/mods-available/oci8.ini
php5enmod oci8
service apache2 restart

Verifions que c’est activé dans php5 :

# php5 -i | grep oci8
/etc/php5/cli/conf.d/20-oci8.ini,
oci8
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20

insserv: loop involving service oracle-xe at depth 2

When installing or upgrading some packages on my server I got:

Preconfiguring packages ...
Setting up initscripts (2.88dsf-31) ...
insserv: script nbclient.08-12-11.18:50:39: service nbclient already provided!
insserv: warning: script 'oracle-xe' missing LSB tags and overrides
insserv: There is a loop between service munin-node and oracle-xe if stopped
insserv: loop involving service oracle-xe at depth 2
insserv: loop involving service munin-node at depth 1
insserv: Stopping oracle-xe depends on munin-node and therefore on system facility `$all' which can not be true!
insserv: script nbclient.08-12-11.18:50:39: service nbclient already provided!
insserv: warning: script 'oracle-xe' missing LSB tags and overrides
insserv: There is a loop between service munin-node and oracle-xe if stopped
insserv: loop involving service oracle-xe at depth 2
insserv: loop involving service munin-node at depth 1
insserv: Stopping oracle-xe depends on munin-node and therefore on system facility `$all' which can not be true!
insserv: exiting now without changing boot order!
update-rc.d: error: insserv rejected the script header
dpkg: error processing initscripts (--configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
initscripts
E: Sub-process /usr/bin/dpkg returned an error code (1)

Debian uses insserv by default in Wheezy which reads the LSB fields (more info here) and to fix this add these lines in the file /etc/init.d/oracle-xe just after « #!/bin/bash »

### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO

debian + php5 + oracle (oci8)

Dans ce post, nous allons ajouté le support d’oci8 dans php5 sur debian squeeze ou 6. Cette extension nous permet de connecter php à une base de données Oracle 11g, 10g, 9i et 8i . Il y a beaucoup d’autre manière d’y arriver mais celle -ci est la plus simple et rapide.

Ajouter ces lignes dans votre /etc/apt/sources.list :

deb http://oss.oracle.com/debian unstable main non-free

Ajouter la clé gpg du mirroir

wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle -O- | apt-key add –

Lancer la mise à jour

aptitude update

Installer le client et les packages nécessaires

aptitude install oracle-xe-client php-pear php5-dev build-essential unzip

Telecharger l’instantclient basic et le sdk à l’adresse

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

J’ai pris les fichiers :

  • instantclient-basiclite-linux32-11.2.0.1.zip
  • instantclient-sdk-linux32-11.2.0.1.zip

Lancer les commandes suivantes dans le répertoire où vous avez téléchargé l’instantclient:

mkdir -p /usr/lib/oracle/xe/app/oracle/product/10.2.0/instantclient/sdk
unzip instantclient-basiclite-linux32-11.2.0.1.zip
unzip instantclient-sdk-linux32-11.2.0.1.zip
cp -rf instantclient_11_2/* /usr/lib/oracle/xe/app/oracle/product/10.2.0/instantclient/

Installation et compilation de l’oci8 :

cd /usr/lib/oracle/xe/app/oracle/product/10.2.0/instantclient
ln -s libclntsh.so.11.1 libclntsh.so
ln -s libocci.so.11.1 libocci.so
pecl install oci8

Entrer la ligne suivante :

instantclient,/usr/lib/oracle/xe/app/oracle/product/10.2.0/instantclient

Si la compilation s’est bien passée, nous allons configurer php à utiliser l’extension oci8 :

echo « extension=oci8.so » > /etc/php5/apache2/conf.d/oci8.ini

ou

echo « extension=oci8.so » > /etc/php5/cli/conf.d/oci8.ini

Normalement c’est la même chose si vous avez php5-cli et libapache2-mod-php5 car ça écrit toujours dans le répertoire /etc/php5/conf.d . On peut tester pour php5-cli en lancant :

php -i | grep oci

Chez moi ça donne :

/etc/php5/cli/conf.d/oci8.ini,
oci8
oci8.connection_class => no value => no value
oci8.default_prefetch => 100 => 100
oci8.events => Off => Off
oci8.max_persistent => -1 => -1
oci8.old_oci_close_semantics => Off => Off
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20