SunshinePHP Developer Conference 2015

Instalación

Configurar PHP con OCI8

Revise la sección previa Requerimientos antes de configurar OCI8.

Para habilitar la extensión OCI8 se ha de configurar PHP con la opción --with-oci8 .

Antes de iniciar el servidor web, OCI8 normalmente necesita diversas variables de entorno de Oracle (véase abajo) para localizar bibliotecas, apuntar a ficheros de configuración, y establecer algunas propiedades básicas como el conjunto de caracteres usado por las bibliotecas de Oracle. Las variables deben ser establecidas antes de que se inicie cualquier proceso de PHP.

El binario de PHP debe vincularse con la misma, o más reciente, versión mayor de las bibliotecas de Oracle con las que se configuró. Por ejemplo, si se construyó OCI8 con las bibliotecas de Oracle 11.2, entonces PHP debería también PHP usarse y ejecutarse con la bibliotecas de Oracle 11.2. Las aplicaciones de PHP pueden conectarse a otras versiones Oracle Database, ya que Oracle posee compatibilidad cliente-servidor entre versiones.

Instalar OCI8 con una extensión compartida

La opciones de configuración shared construye OCI8 como una biblioteca compartida que puede ser cargada dinámicamente en PHP. La construcción de una extensión compartida permite que OCI8 sea actualizada fácilmente sin que tenga impacto sobre el resto de PHP.

Se ha de configurar OCI8 usando una de las siguientes opciones de configuración:

  • Si se usan las bibliotecas » Oracle Instant Client gratuitas, se ha de hacer lo siguiente:

    ./configure --with-oci8=shared,instantclient,/ruta/a/instant/client/lib
    

    Si Instant Client está instalado desde ficheros ZIP, asegúrese de crear el enlace simbólico de la biblioteca primero, por ejemplo ln -s libclntsh.so.12.1 libclntsh.so.

    Si se usa una instalación de Oracle Instant Client basada en RPM, la línea de confiugraicón se parecerá a esta:

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

    Por ejemplo, --with-oci8=shared,instantclient,/usr/lib/oracle/12.1/client/lib

    Nótese que el soporte para Oracle Instant Client apareció primero en PHP 4.3.11 y 5.0.4 y que originalmente se utilizaba la opción --with-oci8-instant-client para configurar PHP.

  • Si se usa una base de datos de Oracle o una instalación completa de Oracle Client, la línea ha de ser:

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

    Asegúrese de que el usuario del servidor web (nobody, www) tiene acceso a las biblitecas, a los ficheros de inicialización y a tnsnames.ora (si se utiliza) bajo el directorio $ORACLE_HOME. Con Oracle 10gR2 podría ser necesario ejecutar la utilidad $ORACLE_HOME/install/changePerm.sh para proporcionar acceso al directorio.

Después de la configuración, siga los procedimientos habituales de construcción de PHP, p.ej., make install. Se creará la extensión compartida oci8.so. Podría ser necesario moverla manualmente al directorio de extensiones de PHP, especificado por la opción extension_dir del fichero php.ini.

Para completar la instalación de OCI8, edite php.ini y añada la línea:

extension=oci8.so

Instalar OCI8 como una extensión compilada estáticamente

Se ha de configurar PHP para incluir OCI8 usando una de las siguientes opciones de configuración:

  • Si se usa Oracle Instant Client, se ha de utilizar lo siguiente:

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

  • Si se usa una base de datos de Oracle o una instalación completa de Oracle Client, la línea ha de ser:

    ./configure --with-oci8=$ORACLE_HOME
    

Después de la configuración, siga los procedimientos habituales de construcción de PHP, p.ej., make install. Después de una compilación satisfactoria no es necesario añadir oci8.so a php.ini. No se requieren pasos adicionales para la construcción.

Instalar OCI8 desde PECL

La extensión OCI8 se puede añadir a una instalación de PHP existente, automática o manualmente, desde » PECL.

Para una instalación automática, siga estos pasos:

  • Si está detrás de un cortafuegos, establezca el proxy de PEAR, por ejemplo:

    pear config-set http_proxy http://mi-proxy.example.com:80/
    

  • Ejecute

    pecl install oci8
    

    Cuando se le pregunte, introduzca el valor de $ORACLE_HOME, o instantclient,/path/to/instant/client/lib.

    Nota: No introduzca la variable $ORACLE_HOME ya que no será expandida. En su lugar, introduzca la ruta real del directorio inicial de Oracle.

Para una instalación manual cuando el comando pecl no esté disponible, descargue el paquete OCI8 de PECL, p.ej. oci8-1.4.10.tgz.

  • Extraiga el paquete:

    tar -zxf oci8-1.4.10.tgz
    cd oci8-1.4.10
    

  • Prepare el paquete:

    phpize
    

  • Configure el paquete, usando $ORACLE_HOME o Instant Client

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

    o

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

  • Instale el paquete:

    make install
    

Después de la instalación manual o automática, edite el fichero php.ini y añada la línea:

extension=oci8.so

Asegúrese de que la directiva de php.ini extension_dir está establecida al directorio donde oci8.so fue instalado.

Instalar OCI8 en Windows

Al usar las bibiotecas cliente de Oracle 10gR2 en Windows, descomente la línea del php.ini extension=php_oci8.dll. Al usar las bibliotecas cliente de Oracle 11gR2 o posterior, descomente extension=php_oci8_11g.dll o extension=php_oci8.dll. Con las bibliotecas de Oracle 12c use extension=php_oci8_12c.dll o extension=php_oci8_11g.dll o extension=php_oci8.dll. Solamente puede estar habilitada una de estas DLLs al mismo tiempo. Las DLLs de versiones posteriores pueden contener más funcionalidad. No todas las DLLs pueden estar disponibles para todas las versiones PHP. Asegúrese de que extension_dir está establecido al directorio que contiene las DDLs de extensiones de PHP.

Si usa Instant Client, establezca la variable de entorno de sistema PATH al directorio de la biblioteca de Oracle.

Establecer el entorno de Oracle

Antes de usar esta extensión, asegúrese de que las variables de entorno de Oracle están establecidas apropiadamente para el usuario del demonio web. Si el servidor web se inicia automáticamente durante el arranque, asegúrese de que el entorno de tiempo de arranque está también configurado correctamente.

Nota:

No establezca las variables de entorno de Oracle usando putenv() en un script de PHP, ya que la bibliotecas de Oracle podrían ser cargadas e inicializadas antes de que el script se ejecute. Las variables establecidas con putenv() podrían ocasionar conflictos, fallas, o comportamientos impredecibles. Algunas funciones podrían funcionar, mientras que otras darían errores imperceptibles. Las variables deberían estar configuradas antes de que se inicie el servidor web.

En Red Hat Linux y sus variantes, exporte las variables al final de /etc/sysconfig/httpd. Otros sistemas con Apache 2 podrían usar un script envvars en el directorio bin de Apache. Una tercera opción, la directiva SetEnv de Apache en httpd.conf, podría funcionar en algunos sistemas, pero se sabe que es insuficiente en otros.

Para verificar que las variables de entorno están establecidas correctamente, use phpinfo() y compruebe la sección Environment (no la de Apache) que contiene las variables requeridas.

Las variables que podrían ser necesarias están incluidas en la siguiente tabla. Consulte la documentación de Oracle para más información sobre todas las variables disponibles.

Variables de entorno comunes de Oracle
Nombre Propósito
ORACLE_HOME Contiene el directorio del software completo de Oracle Database. No la establezca cuando use Oracle Instant Client ya que no es necesaria y podría causar problemas de instalación.
ORACLE_SID Contiene el nombre de la base de datos de la máquina local a la que conectarse. Na hay necesidad de establecerla si se usa Oracle Instant Client, o si siempre se proporciona el parámetro de conexión a oci_connect().
LD_LIBRARY_PATH Establézcala (o su equivalente de plataforma, como DYLD_LIBRARY_PATH, LIBPATH, o SHLIB_PATH) a la ubicación de las bibliotecas de Oracle, por ejemplo, $ORACLE_HOME/lib o /usr/lib/oracle/11.1/client/lib. Esta variable no es necesaria si las bibliotecas está localizadas mediante un mecanismo de búsqueda diferente, como con ldconfig o LD_PRELOAD.
NLS_LANG Esta es la variable principal para configurar el conjunto de caracteres y la información de globalización usados por las bibliotecas de Oracle.
ORA_SDTZ Establece la zona horaria de la sesión de Oracle.
TNS_ADMIN Contiene el directorio donde residen los ficheros de configuración de Oracle Net Services, tales como tnsnames.ora y sqlnet.ora. No es necesaria si la cadena de conexión oci_connect() utiliza la sintaxis de nombramiento sencillo de conexiones, como localhost/XE. No es necesaria si los ficheros de configuración de red está en las ubicaciones predeterminadas, como $ORACLE_HOME/network/admin o /etc.
Las variables de entorno de Oracle que se usan con menos frecuencia incluyen TWO_TASK, ORA_TZFILE, y las diversas configuraciones de globalización de Oracle como NLS* y las variables ORA_NLS_*.

Resolución de problemas

El problema más común al instalar OCI8 es no tener el entorno de Oracle correctamente establecido. Esto, normalmente, aparece como un problema al utilizar oci_connect() o oci_pconnect(). El error podría ser un error de PHP tal como Call to undefined function oci_connect(), un error de Oracle como ORA-12705, o incluso que Apache falle. Compruebe los ficheros de registro de Apache para los errores de arranque y lea las secciones sobre la resolución de este problema.

Mientras que los errores de red como ORA-12154 u ORA-12514 indican un problema con el nombramiento de redes o de configuraicón de Oracle, la raíz de la causa podría ser debida a que el entorno de PHP no esté correctamente configurado, y por lo tanto, las bibliotecas de Oracle no son capaces de localizar el fichero de configuración tnsnames.ora.

En Windows, el tener múltiples versiones de Oracle en la misma máquina puede ocasionar fácilmente que las bibliotecas fallen, a menos que se asegure de que PHP utilice solamente la versión correcta de Oracle.

Una utilidad para examinar las bibliotecas que están siendo buscadas y cargadas puede ayudar a resolver problemas de bibliotecas ausentes o que fallen, particularmente en Windows.

Nota: Si el servidor web no se inicia o falla durante el arranque

Compruebe que Apache está vinculado con la biblioteca pthread:

# ldd /www/apache/bin/httpd
  libpthread.so.0 => /lib/libpthread.so.0 (0x4001c000)
  libm.so.6 => /lib/libm.so.6 (0x4002f000)
  libcrypt.so.1 => /lib/libcrypt.so.1 (0x4004c000)
  libdl.so.2 => /lib/libdl.so.2 (0x4007a000)
  libc.so.6 => /lib/libc.so.6 (0x4007e000)
  /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

Si libpthread no se muestra, reinstale Apache:

# cd /usr/src/apache_1.3.xx
# make clean
# LIBS=-lpthread ./config.status
# make
# make install

Por favor, observe que en algunos sistemas como UnixWare, es libthread en lugar de libpthread. PHP y Apache tienen que estar configurados con EXTRA_LIBS=-lthread.

add a note add a note

User Contributed Notes 46 notes

up
2
Sergey
2 years ago
Lost a day on trying to make work oci8 & pdo_oci extensions in php-fpm 5.3 on OpenSuSE 12.2 (64bit) with latest oracle instant client 11.2.0.3.0.
Any of two works normally with generic instructions. But both extensions caused crash in oci_connect().

Solution was simple add ORACLE_HOME variable BEFORE running php-fpm.

/etc/profile.d/oracle.sh
#!/bin/bash
ORACLE_HOME=/usr/lib/oracle/11.2/client64
LD_LIBRARY_PATH=$ORACLE_HOME/lib
NLS_LANG=american_america.utf8
export ORACLE_HOME LD_LIBRARY_PATH NLS_LANG

/etc/init.d/php-fpm
.....
. /etc/rc.status
. /etc/profile.d/oracle.sh # add this after rc.status (note: dot & space)
.....

After "service php-fpm restart" works normally. Hope this helps.
up
2
samantha dot vincent at gmail dot com
2 years ago
Windows Server 2008 Standard Edition Service Pack 2 i586
PHP Version 5.4.4
XAMPP 1.8.0

This is what finally got it working for me:

Downloading win32_11gR2_client.zip from the Oracle website.

It was really hard to find, but I got there by choosing Downloads > Oracle Database 11g Release 2 then clicked the "See All" link on the far right of the Microsoft Windows (32-bit) download links under (11.2.0.1.0)

On this page the second option down is a link to download just the client libraries.

I unzipped it, and ran setup.exe

I chose Runtime, I couldn't get InstantClient to work.

I used the defaults for Oracle Base and Oracle Home, make sure to write these down you need them.
Oracle Base: "D:/app/Administrator"
Oracle Home:  "D:/app/Administrator/product/11.2.0/client_1"

I chose just English as the language.

Next'd through the rest of the installer... The nice thing about this full install is that it sets the Windows Path variable for you, and it has the required library files.

In my php.ini file located in /xampp/php/php.ini
Remove the semicolon from the front of the line: extension=php_oci8_11g.dll

In my apache httpd.conf file in /xampp/apache/conf/httpd.conf

Add the following SetEnv lines to the end of the <Directory "C:/xampp/htdocs"> This is where you use the oracle base and home paths you wrote down earlier while installing the oracle client ;) This is what mine looks like without all the comments.

<Directory "C:/xampp/htdocs">
   
    Options Indexes FollowSymLinks Includes ExecCGI

    AllowOverride All

    Order allow,deny
    Allow from all
   
    SetEnv ORACLE_BASE "D:/app/Administrator"
    SetEnv ORACLE_HOME "D:/app/Administrator/product/11.2.0/client_1"
    SetEnv ORACLE_SID ""
    SetEnv NLS_LANG "AMERICAN_AMERICA.WE8MSWIN1252"

</Directory>

I then created a php file and attempted a connection like this:

<?php
$db
= "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = TCSDB07)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = IPROD)))";

$conn = oci_connect('username', 'password', $db);
if(!
$conn){
   
$e = oci_error();
   
trigger_error(htmlentities($e['message'], ENT_QUTOES), E_USER_ERROR);
}
?>
up
2
alvaro at demogracia dot com
6 years ago
If you've followed the instructions and you can't even connect to the DB server, welcome to the Oracle hell. Most of the information you'll find is deprecated, incomplete, not for your platform, unnecessary or just plain wrong.

Typically, you won't need at all those complicate setups you'll read about and they'll probably make things harder. I suggest you get Systernal's "Filemon" utility (for Windows, in Unix you may do with strace) and find out what exact config files and DLLs are being tried by php.exe (or httpd.exe if PHP runs as Apache module or...). Pretty often, the issue is that (e.g.) TNSNAMES.ORA does not have the correct line ending or Apache is looking for a DLL that does not even exist in your hard disc; learning that prevents you to waste time adding more and more useless environmental variables.

Goog luck.
up
1
ashnazg at php dot net
6 years ago
Do not underestimate the importance of NLS_LANG in your environment.

The Oracle error "ORA-03106: fatal two-task communication protocol error" is indicative of not having NLS_LANG set.

In my case, I had a successfully processing INSERT statement followed by a failing SELECT statement that was resulting in that ORA-03106 error.  The successful INSERT implied that all Oracle environment settings were fine.  Ultimately we found that the NLS_LANG was not set, and I have to assume that only the SELECT of data back from the database actually _needed_ it, and therefore it was the SELECT statement that triggered the failure.  Though, that is all speculation.
up
1
david dot reynoldsat at ipl dot com
7 years ago
I had a problem loading php_oci8.dll with php 5.2, Apache, and windows XP - a module not loaded error, on every apache restart.
I eventually found that I had to add the oracle instantclient library path to the %PATH% under SYSTEM and not under USER.  Doing that, and then rebooting, fixed the error - as Apache is starting as a service (outside the user setup).
up
1
ben at onshop dot co dot uk
9 years ago
I spent ages trying work out why I was getting the following message when when using ocilogon() on Windows 2000 using PHP 4 and 5:

ORA-03106 Fatal two-task communication protocol error

This problem is occurs when PHP cannot find ORACLE client environmental variables.

The environmental variables can be set in several ways:

1. Within the root 'Directory' directive on Apache httpd.conf:

<Directory "d:/path/to/webroot">
  SetEnv ORACLE_BASE "c:/oracle"
  SetEnv ORACLE_HOME "c:/oracle/ora81"
  SetEnv NLS_LANG "american_america.WE8DEC"
  SetEnv NLS_CHARACTERSET "WE8DEC"
  SetEnv NLS_NCHAR_CHARACTERSET "AL16UTF16"
</Directory>

or

2. Within Windows:

Go to the Control Panel>System>Advanced>Environmental Variables

Then enter a name value/pair for each of the variables.

3. Using putenv() statements in the PHP file prior to using ocilogon(). This is not ideal because the statements are required evertime you wish to connect to Oracle.
up
1
NOSPAMPLZ!esartoni at omniaglobal dot net
11 years ago
I had a little problem with ocilogon but only with RedHat 8.0. It always returned some kind of error during connection like 'OCISessionBegin - ... invalid character', or 'OCISessionBegin - ... missing or invalid option in ...'

I have finally found what is this problem! You have to change your LANG enviroment variable disabling UTF-8. Example: LANG=en_US.UTF-8 should become LANG=en_US.
up
1
lore_giver at lycos dot co dot uk
11 years ago
Running Oracle 9i on a
Solaris 9 (64 bit) platform with a Sun Server E250:
Apache version 1.3.27
PHP version 4.3.1

I was first getting "...wrong ELF class: ELFCLASS64.."
while doing a ./configure with the --with-oci8 and --with-oracle parameters.

After some unsuccessfull searched I renamed the $ORACLE_HOME/lib to $ORACLE_HOME/lib.org and then renamed the
$ORACLE_HOME/lib32 to $ORACLE_HOME/lib

Thereafter it went passed this config, but now failed on
not being able to find a libwtc9.so file which was in the
$ORACLE_HOME/lib directory  (this message was displayed in the debug.log in the php source directory).

After setting the Environment variable:
LD_LIBRARY_PATH=$ORACLE_HOME/lib
I was able to compile without any errors and 'make' and 'make install' ran smoothly.

I only had to add the php type in the httpd.conf (in your apache conf directory eg. /usr/local/apache/conf)..
AddType application/x-httpd-php .php
to get the php to work again...

I had to then reverse the $ORACLE_HOME/lib swop on top since php was now having problems with the 32 bit version of the library...so switched it back to 64 and my php script worked....

Hope this helps some out there with similar problems..

Cheers
up
1
Anonymous
11 years ago
Configuring/Compiling PHP as a DSO with Oracle support from source on a Sun Solaris 8 box.  We had already installed Oracle 9.2.0 client tools.

1. Make sure the following tools are installed

    autoconf
    automake
    bison
    flex
    gcc
    make
    gzip
   
    They can be downloaded from http://www.sunfreeware.com.
   
2.  Make sure Apache is installed with DSO support.  We ran the Apache configure/compile like so:

    LIBS=-lpthread ./configure \
    --prefix=/usr/local/apache \
    --enable-module=most \
    --enable-shared=max
   
   
    make
    make install
   
3.  If you haven't already, install the Oracle client tools.
4.  Make sure the following environment variables are set correctly and are accessible by all users.  We set them in /etc/profile.

    ORACLE_HOME
    ORACLE_BASE
    NLS_LANG
    ORA_NLS33
    ORACLE_TERM
    LD_LIBRARY_PATH
   
    (technically, only $ORACLE_HOME is required, but you'll want to set the rest in order to make sure things run smoothly afterward)
   
5.  Make sure '/usr/ccs/bin' is in your path.  If not, add it.
6.  Unpack PHP source (php-4.2.3):

    gunzip php-4.2.3.tar.gz
    tar xvf php-4.2.3.tar
    cd php-4.2.3

   
7.  Run PHP configure like so :

    CC=gcc ./configure --with-apxs=/usr/local/apache/bin/apxs \
    --with-config-file-path=/etc \
    --with-mysql \
    --enable-ftp \
    --with-oci8=/path/to/ORACLE_HOME \
    --with-oracle=/path/to/ORACLE_HOME \
    --enable-sigchild
   
8.  Run make:  make
9.  Run this as root:  make install
10.  Change the LoadModule line in httpd.conf to include the fully qualified path.  For us:

    LoadModule php4_module        /usr/local/apache/libexec/libphp4.so
   
11.  Make sure the PHP files types are recognized in your httpd.conf file:

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
   
12.  Test the configuration:

    /usr/local/apache/bin/apachectl configtest
   
    It should return "Syntax OK"
   
13.  Bounce Apache:

    /usr/local/apache/bin/apachectl restart
   
   
14.  Here's a simple PHP script to test the setup.  If you don't have access to the default tables Oracle provides, change the connections/tablenames/fields to match your setup:

    <?php

    $db_conn
= ocilogon("scott", "tiger");

   
$cmdstr = "select ename, sal from emp";
   
$parsed = ociparse($db_conn, $cmdstr);
   
ociexecute($parsed);
   
$nrows = ocifetchstatement($parsed, $results);
    echo
"Found: $nrows results<br><br>\n";

    echo
"<table border=1 cellspacing='0' width='50%'>\n";
    echo
"<tr>\n";
    echo
"<td><b>Name</b></td>\n";
    echo
"<td><b>Salary</b></td>\n";
    echo
"</tr>\n";

    for (
$i = 0; $i < $nrows; $i++ ) {
          echo
"<tr>\n";
          echo
"<td>" . $results["ENAME"][$i] . "</td>";
          echo
"<td>$ " . number_format($results["SAL"][$i], 2). "</td>";
          echo
"</tr>\n";
    }

    echo
"</table>\n";

   
?>
up
1
kakukkfu at mailbox dot hu
12 years ago
Better to insert needed variables into apache(!) (or your webserver - respectively) start script.

For example on UNIX systems /etc/init.d/apache would contain following lines before anything else:

#!/bin/bash

if [ -f ~oracle/.profile ]; then
        source ~oracle/.profile
fi

The ~oracle/.profile has the appropiate settings to start an Oracle database so it is always up-to-date for PHP, too. (If settings are changed, don't forget to restart your webserver.) This way you just no need to worry what to include or define for PHP.
up
1
devolver at iastate dot edu
12 years ago
I spent several hours tracking down error ORA 24374, which would result from only *SOME* of my select statements.  This error would be caused if I made a query that would return any non-numerical value.  I am running an Apache 1.3.x webserver and PHP 4.2.1.

The fix is to add entries in your httpd.conf file that would export your environment settings.  I added these three lines and everything worked like a charm!
SetEnv ORACLE_HOME  /path/to/oracle/home
SetEnv ORA_NLS33  /path/to/oracle/home/ocommon/nls/admin/data
SetEnv NLS_LANG AMERICAN

Obviously, if your NLS_LANG is different, you should set it to whatever your NLS_LANG actually is.  Ask your friendly DB admin for this information.

Hope this helps someone who treads down the path that I just followed!

Trent
up
1
shmengie_2000 at yahoo dot com
14 years ago
couple of notes about startup/shutdown on linux:  (redhat, maybe others)

export LD_PRELOAD=/usr/lib/libpthread.so

Caused the start/stop script to fail to stop the httpd process. 
The LD_PRELOAD environment var caused the 'ps' command to core dump.  I went bald figuring that out.

Easiest fix I could think of was to move all the oracle/php varialble exports so they are only set in the start section of the httpd script.

Never thought setting those vars globally in the script would cause problems.  That's what I get for thinking...

One other note:  Make sure the httpd process is shutdown before Oracle.

eg:
/etc/rc.d/rc0.d/K15httpd
/etc/rc.d/rc0.d/K25Oracle

Lingering connections to oracle may cause shutdown to take forever.

gl & hf

-Joe
up
0
wingjeeplau at gmail dot com
1 year ago
In Ubuntu the setting is in file /etc/apache2/envvars
up
0
Saxon Leung
2 years ago
Spending long time in researching how to install this on a freshly installed [Red Hat-based (RHEL, CentOS, Fedora)] Linux, and finally I come to this:

1) Download & install

#yum install oracle-instantclient-basic
#yum install oracle-instantclient-devel

or

Download:
oci8-1.4.7.tgz
oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

#rpm -i oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
#rpm -i oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm

2) Check PHP version:

#rpm -qa | grep php

It should looks sth like this:
php-devel-5.3.10-1.w5
php-pdo-5.3.10-1.w5
php-ldap-5.3.10-1.w5
php-cli-5.3.10-1.w5
php-mysql-5.3.10-1.w5
php-5.3.10-1.w5
php-common-5.3.10-1.w5

3) Update if needed by:

#yum --enablerepo=webtatic update php

** Make sure you have php-devel installed before updating to a newer version, or you might have problem to add package back. If it happened, you\\'ll have to reinstall all php packages (sadly I did):

#yum remove php-common
#yum --enablerepo=webtatic install php

4) Remember to install a C compiler for installation use:
#yum install gcc

5) Unzip oci8-1.4.7.tgz:
#tar xvzf oci8-1.4.7

6) Run phpize (php-devel required):
# phpize

7) Setup Config:
# ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib

8) Add a sym-link to the SDK header files (Comes with the instantclient-devel)

#ln -s /usr/include/oracle/11.2/client64/ /usr/lib/oracle/11.2/client64/lib/include

** The installation defaults to use 1 dir path only, so the missing SDK files need to add back to that directory, by adding a sym-link \\"include\\" under the lib folder.

9) Compile and install:
#make all install

[Please note that I'm installing on a 64-bit platform so links are pointing at client64 instead of client]
up
0
modir at huanga dot com
3 years ago
For those of you who would like to install this extension on an RedHat/CentOS server. It is actually pretty simple.

Here is what you have to do:
1) Download the following RPM from Oracle: oracle-instantclient11.2-basiclite-11.2.0.2.0.x86_64.rpm (Version number can be newer and check if you need the 64bit version or not). And then install it on the server.

2) yum install php-oci8

3) And as the last step you edit /etc/sysconfig/httpd and write the following line at the end: export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib/ (Attention: Path changes depending on the version you have downloaded from the Oracle website.)
up
0
beer at myplace dot now
5 years ago
I was experiencing issues with Unicode characters being saved incorrectly to my ORA 10 DB. Issue was tracked to not having a NLS_LANG environment variable specified - set this correctly in the Apache environment and the issue was resolved.
up
0
benstendahl at hotmail dot com
5 years ago
When using PHP on an IIS server (Windows Server 2000+):

After installing the Oracle Instant Client and adding it to the "PATH" Environment Variable, be sure that you also add "Read & Execute" privileges to the Oracle Instant Client directory for the IIS user designated for the site.  This is especially necessary if IIS has been hardened using the IIS Lockdown tool (http://technet.microsoft.com/en-us/library/dd450372(WS.10).aspx) as users must be explicitly granted permissions from the web.
up
0
nicodenboer (at) yahoo (dot) com
5 years ago
Hi, I use Oracle Database 10g Express Edition Release
10.2.0.1.0 on a Linux workstation for dev purposes, along
with Apache 2 and PHP5. So far I have used it on Kubuntu 8.04.
To get things working on a recently installed notebook with openSUSE
11.0 was a bit more complicated. So I hope someone will be able to
benefit from our experiences. Here is our howto:

# Use the package manager to install the packages php5-pear and
php5-dev, if not installed yet.

# Download the instantclient_11_1, zip files basic, sdk, sqlplus from the Oracle web site

# Switch to user root here, since not all commands to some work sudo

# Unzip these files to /opt/oracle/.
# As a result you will see a dir instantclient_11_1 appearing.

ln -s /opt/oracle/instantclient_11_1/libclntsh.so.11.1 \
   /opt/oracle/instantclient_11_1/libclntsh.so 
ln -s /opt/oracle/instantclient_11_1/libclntsh.so.11.1 \
   /usr/lib/libclntsh.so
ln -s /opt/oracle/instantclient_11_1/libnnz11.so \
   /usr/lib/libnnz11.so
ldconfig # to make sure the system will be able to find the libs

pecl install oci8 # interactively enter option 1,
# then instantclient,/opt/oracle/instantclient_11_1,
# then enter

# if needed, add extension=oci8.so to your php.ini

/etc/init.d/apache2 reload

# finished!

Kind regards,
Nico den Boer
up
0
mike at macgirvin.com
6 years ago
Some notes to save somebody some grief:

Installing the Oracle libraries and access module into an existing PHP5 installation on Debian etch without rebuilding php...

First grab the Linux instantclient from oracle.com - you'll also need the client SDK kit. Here I'm using instantclient 11.1

create a directory for these such as /home/oracle and unpack both of them to that directory.

Go into the oracle directory (and into the instantclient_11_1 directory) and create a symlink:

$ ln -s libclntsh.so.11.1 libclntsh.so

Grab the oci8 PECL package and unpack it somewhere (~/oci).

Make sure you have the following packages (in addition to php5, php5-cli, apache2, etc).

  php5-dev

  libaio1

  php-pear


Go to the oci8 directory (~/oci/).

You need to run 'pecl build' once to create the configure script.

$pecl build

But the problem is that pecl build will claim the files are installed and they are not. I wasted half a day on this one. Now go into the oci8-1.3.0 directory and build again by hand:

$ cd oci8-1.3.0

$ ./configure --with-oci8=instantclient,/home/oracle/instantclient_11_1

$ make

Fix any errors/warnings before continuing

Don't make install, which won't work.

$ cp ./modules/oci8.so /usr/lib/php5/20060613+lfs

Replace 20060613+lfs with whatever module directory has been setup for you in /usr/lib/php5

Create /etc/php5/conf.d/oci8.ini:

----

extension=oci8.so

----

Now run the php cmdline in verbose mode (php -v) and see if everything loaded. Fix it if it didn't.

You may need some env variables setup in your /etc/init.d/apache2 file to make everything work and actually execute queries, but a phpinfo() at this point should show your oci8 extension. See the php.net Oracle pages if you need help with the env variables.

Restart the web server

$ /etc/init.d/apache2 restart
up
0
jay dot couture at gmail dot com
7 years ago
# Here's what it took to get it going for me on Red Hat on
# x86_32 w/ 10gr2 and php5.1.2
# I sincerely appreciate all of the other poster's notes.
# It was a combination of a few
# of them to get mine configured. My note should reflect this:

# install the instantclient basic and sdk like this
# note: the original poster had you install into a lib subdirectory,
# but when I tried this it couldn't find the sdk files. So I moved
# the files in lib into the parent directory as
# shown below. Actually I copied them, YMMV
mkdir -p /usr/lib/oracle/10.2.0.2/client
unzip -jd /usr/lib/oracle/10.2.0.2/client
    instantclient-basic-linux-x86-32-10.2.0.2-20060331.zip
mkdir -p /usr/include/oracle/10.2.0.2/client
unzip -jd /usr/lib/oracle/10.2.0.2/client
    instantclient-sdk-linux-x86-32-10.2.0.2-20060331.zip
ln -s /usr/lib/oracle/10.2.0.2/client/libclntsh.so.10.1
    /usr/lib/oracle/10.2.0.2/client/libclntsh.so

# make the full client use instantclient's files
cd /app/oracle/product/10.2.0/db_1
mv lib oldlib
ln -s /usr/lib/oracle/10.2.0.2/client/lib lib
ln -s /usr/include/oracle/10.2.0.2/client include

#php configure line is:
    ./configure --with-oci8=instantclient,/usr/lib/oracle/10.2.0.2/client

# I had to do this, or the OCI8 would not compile when
# I ran make on PHP5.1.2 I did not do this originally when I
# had the files in the lib sudirectory (see my note above) so
# that may be the true issue.
export LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.2/client:$LD_LIBRARY_PATH

make

make install

#In apache2 edit the envvars and add
LD_LIBRARY_PATH="/usr/local/apache2/lib:
    /usr/lib/oracle/10.2.0.2/client:$LD_LIBRARY_PATH"
TNS_ADMIN="/usr/lib/oracle/10.2.0.2/client"
LANG=en_US
export LD_LIBRARY_PATH LANG TNS_ADMIN

#Restart Apache

Jay
up
0
rainer dot klier at gmx dot at
8 years ago
estoreic (note from 15-May-2006 10:54) is right.

there seems to be a problem with the oci8-api-functions in php 4.4.x.

there are error-messages like these in the error_log:
child pid 22297 exit signal Segmentation fault (11)
*** glibc detected *** double free or corruption (out): 0x00000000019f4730 ***
*** glibc detected *** double free or corruption (!prev): 0x0000000001111d90 ***
*** glibc detected *** corrupted double-linked list: 0x0000000001111d50 ***

using php 4.4.x with oracle 10.x is impossible, until you do the following:
1. download latest oci8-package from http://pecl.php.net/package/oci8
2. extract package somewhere
3. go to php-4.4.x-source directory
4. rm -rf ext/oci8
5. cp extraceted oci8-1.2.x directory to/as ext/oci8
6. make distclean
7. ./buildconf --force
8. ./.configure (with the options you need)
9. make
10. only for x86_64:
create pear-install.ini:
-----------------------------------------------
[PHP]

memory_limit = 128M      ; Maximum amount of memory a script may consume (8MB)
------------------------------------------------

11. edit Makefile:
replace:
PEAR_INSTALL_FLAGS = -n -dshort_open_tag=0 -dsafe_mode=0
with:
PEAR_INSTALL_FLAGS = -cpear-install.ini -dshort_open_tag=0 -dsafe_mode=0

12. make install

have fun!
oracle connections will work now!
up
0
f dot kheiri at ucl dot ac dot uk
8 years ago
To compile PHP 4.4.2 with OCI8 / Oracle 9i / AIX 5.2 (64-bit) / GCC

PHP will automatically compile against the Oracle 64-bit libraries, which PHP being a 32-bit app, will cause "make" to fail (though it will configure fine). Here's how to avoid this:

1. replace your PHP's ext/oci8 directory with the latest ext/oci8 directory downloadable from PECL - then remove the old directory entirely

2. rebuild configure by running:

./buildconf --force

...in PHP's root directory. This will rebuild the configure script.

3. using a tool like sed, in your configure file replace all instances of /path/to/oracle/lib with /path/to/oracle/lib32 - note, this may require GNU's autoconf, m4 and gnumake.

4. export LD_LIBRARY_PATH=/path/to/oracle/lib32

5. ./configure --with-oci-8=/path/to/oracle (and any other options)

Then, the usual make and make install.
up
0
Anonymous
8 years ago
# here's what it took to get it going for me on rhel4 on x86_64 w/ 10gr2 and php5.0.5
# hopefully this will save someone a little grief
# first you must install the 10.2 full client in /app/oracle/product/10.2.0/db_1
# follow all the instructions. This part will be a bitch.

# install the instantclient basic and sdk like this
mkdir -p /usr/lib/oracle/10.2.0.2/client/lib
unzip -jd /usr/lib/oracle/10.2.0.2/client/lib instantclient-basic-linux-x86-64-10.2.0.2-20060228.zip
mkdir -p /usr/include/oracle/10.2.0.2/client
unzip -jd /usr/lib/oracle/10.2.0.2/client instantclient-sdk-linux-x86-64-10.2.0.2-20060228.zip
ln -s /usr/lib/oracle/10.2.0.2/client/lib/libclntsh.so.10.1 /usr/lib/oracle/10.2.0.2/client/lib/libclntsh.so

# make the full client use instantclient's files
cd /app/oracle/product/10.2.0/db_1
mv lib oldlib
ln -s /usr/lib/oracle/10.2.0.2/client/lib lib
ln -s /usr/include/oracle/10.2.0.2/client include

php configure line is: --with-oci8=/app/oracle/product/10.2.0/db_1/
up
0
soef at tjah dot net
8 years ago
To install this in gentoo linux you will need to do some weird stuff:

-  Make sure you have this use flags set: "dba cli pcre xml zlib oci8-instant-client"
- Unmask PHP (5.1.1) by placing "dev-lang/php ~x86" in /etc/portage/package.keywords
- Unmask oracle-instantclient-basic (10.2.0.1-r1) by placing "dev-db/oracle-instantclient-basic ~x86"
- Download oracle files from "http://otn.oracle.com/software/tech/ oci/instantclient/htdocs/linuxsoft.html" (You have to make an account and login, in order to download the packages:

    * instantclient-basic-linux32-10.2.0.1-20050713.zip
    * instantclient-sdk-linux32-10.2.0.1-20050713.zip

- Place the downloaded packages in "/usr/portage/distfiles"
- "emerge apache dev-lang/php5" (If you done right, the build for the instantclient will be selected automaticly.
- Configure your "/etc/conf.d/apache2" to make sure you have "-D PHP5" in your "APACHE_OPTS"
up
0
scoop at subindie dot com
8 years ago
Regarding compiling with the recently updated OCI8 Extension (http://pecl.php.net/package/oci8).

I ran into problems when statically compiling, such as numerous "undefined reference to `zif_oci_***'" errors.  Since I likely won't be the only one to run into this problem, here's some helpful hints:

If you've previously compiled your php installation, first: make clean

Then replace the existing php-x.x.x/ext/oci8 directory with the latest package from: http://pecl.php.net/package/oci8

./buildconf --force
./config ..
make
up
0
denis dot delamarre at chu-rennes dot fr
9 years ago
php5 + Apache 2 + solaris 2.10 + oracle9i (64bits)

'./configure' '--with-oracle=/prod/dba/oraeve/ora9i' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-zlib' '--with-gd' '--without-mysql' '--with-oci8=/prod/dba/oraeve/ora9i'

fail with :
ld: fatal : fichier libclntsh.so : wrong elf class : ELFCLASS64

the solution is between ./configure and make command to edit Makefile and replace /ora9i/lib  with  /ora9i/lib32

all it's ok
up
0
MSapp
9 years ago
Problems compiling 5.0.4 with Oracle Instant Client 10? (i.e. cannot find -lirc)

Remove the "-lirc" from sdk/demo/sysliblist and rerun configure.
up
0
tof
9 years ago
If you want the change NLS_LANG (e.g.:  NLS_LANG="FRENCH_FRANCE.WE8ISO8859P1") don't forget to also set LC_ALL and LANG (e.g.: LC_ALL=french and LANG=french) else you'll have a ORA-01756 when you try to call ocilogon.
up
0
kucerar at hhmi dot org
9 years ago
Great Solaris patch!  Finally built.  Here's some tips on connecting:

Just made this on solaris8 32bit, actually works.

1) put everything in one directory
2) unsetenv ORACLE_HOME
3) set the env vars LD_LIBRARY_PATH and SQLPATH and TNS_ADMIN(if you have it) to that directory.
4) use one of the other easy connection notations here

http://www.oracle.com/technology/
docs/tech/sql_plus/10102/readme_ic.htm

These env vars worked when put at the top of apachectl script as well.

To build you may have to fake it out with an ORACLE_HOME var,  but unset it later.  You may also have to fake out the build by putting header files where it is looking for them,  e.g. in the rdbms/demo directory or some such other place.

When running though,  make sure you have only the files required in only one directory.

Oracle has not put up a link to the 32bit solaris sqlplus--you have to guess it--it's there though:

http://download.oracle.com/otn/solaris/instantclient/
instantclient-sqlplus-solaris32-10.1.0.3.zip
 
...and don't forget to add ".world" on to the end of your SID. It's very common to have to specify DBNAME.WORLD to connect.
up
0
neogodo at yahoo dot com dot br
10 years ago
Hey guys!!!!

I have all these problems and when are solved a php show this:

_oci_server ORA-12159:connection text especified is too long

It's simple!!!

  In the TNSNAMES.ORA remove all space, tab, carriage return on the conection string and, wallah!!! All work fine!!!

  More info:

   PHP 5.0.0  with Oci8
   Apache 1.3

Regards,
Romolo (neogodo@yahoo.com.br).
DBA Oracle
Brazil - SP - Sao Paulo
up
0
mark at magpies dot net
10 years ago
For those trying to use the Oracle Instant Client 10g in a win32 environment, heres a nice easy howto. If you fully read the docs properly and understand what your reading you will be able to set it up, but if like me you want a quick easy fix, heres how I did it.

1. Download and install the Oracle Instant Client to where ever (lets say  c:\ora\client  )
2. Add your connect info, copy a previously created or provided tnsnames.ora file to the above directory.
3. Change Path in the Environment Variables area to add this directory to the path. ie.  c:\ora\client;%SystemRoot%;<and so on>
4. Open regedit and add a Key called ORACLE to HKEY_LOCAL_MACHINE\SOFTWARE
5. To the ORACLE key add a string value called TNS_ADMIN and assign it the directory above (ie. c:\ora\client )  So you end up with KEY_LOCAL_MACHINE\SOFTWARE\ORACLE\TNS_ADMIN = c:\ora\client
6. Set php to use Oci8 extension and bobs your uncle
7. Reboot.

Option 7 was required as the oci8 extension or php wouldn't pick up the path change. Also my problem was how to use other programs like sqlplus without creating extra Environment Variables etc the TNS_ADMIN / tnsnames.ora part makes that simpler and allows you to call things the same as you would before.

PS: This should apply to all the Instant Clients. I haven't tried it with any others but 10g though.

Hope this helps.
up
0
ed000001 at hotmail dot com
10 years ago
If you get your connectivity working with putenv on ORACLE_SID and ORACLE_HOME, but you do not want to use putenv because you want safemode on. You will need to pass these from your environment variables.  Somehow setenv in httpd.conf did not do the trick for me... the values are set but the connectivity does not work.  Then you will need to set the environment in your /etc/init.d/apachectl or /etc/profile and use a "PassEnv ORACLE_HOME ORACLE_SID" directive in httpd.conf so that these variables are picked up by php.

However, when you suexec in Apache 2.0, the server will only allow you to pass a given set of variables which are defined in the apache source code in the file apache-dir/support/suexec.c

In order to pass ORACLE_SID and ORACLE_HOME to PHP you need to add these to that file.  The relevant changed piece of code where I added "ORACLE_" looks something like this:

char *safe_env_lst[] =
{
    /* variable name starts with */
    "HTTP_",
    "SSL_",
    "ORACLE_",

    /* variable name is */
...

You will have to do a "make clean", "./configure", "make", "make install".  Do not forget to do the "make clean" or the apache changes will not be picked up.

Here is a nice php test script :)

<?php // test-oracle.php

   
function dump_array($a_value)
    {
       
reset($a_value);
        for (
$s_str = '' ; list($s_key, $x_value) = each($a_value) ;  )
        {
           
$s_str .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
                     
"<span style=\"color:green\">[</span>$s_key<span style=\"color:green\">]</span> = ".
                     
"<span style=\"color:red\">[</span>$x_value<span style=\"color:red\">]</span><br />";
        }
       
reset($a_value);
        echo
$s_str;
    }

#putenv("ORACLE_SID=ORTD");
#putenv("ORACLE_HOME=/u01/app/oracle/product/9.2.0.1.0");
$ORACLE_SID = getenv("ORACLE_SID");
$ORACLE_HOME = getenv("ORACLE_HOME");
echo
"ORACLE_SID = $ORACLE_SID<br>";
echo
"ORACLE_HOME = $ORACLE_HOME<br>";

   
$cn = ociplogon('scott', 'tiger');
echo
"cn = $cn<br />\n";
   
$st = ociparse($cn, "select tname from tab");
echo
"st = $st<br />\n";
   
$ex = ociexecute($st,OCI_COMMIT_ON_SUCCESS);
echo
"ex = $ex<br />\n";
   
$mr = ocifetchinto($st,$xx,OCI_ASSOC);
    while (
$mr )
    {
       
dump_array($xx);
       
$mr = ocifetchinto($st,$xx,OCI_ASSOC);
    }
   
$fr = ocifreestatement($st);
echo
"fr = $fr<br />";
   
ocicommit($cn);
   
ocilogoff($cn);
?>
up
0
oddbec_no_more_spam_kthx at online dot no
10 years ago
I had trouble with norwegian characters using oracle 8.7.1 / php 4something and Apache 2.

The only trouble was that '?' appeared instead of the norwegian characters.

The solution to it all was to add this to the apachectl script:

export NLS_LANG="norwegian_norway.WE8ISO8859P1"
export ORACLE_BASE="/home/oracle"
export ORA_NLS33="/home/oracle/ocommon/nls/admin/data"
export ORACLE_TERM="ansi"
export ORACLE_HOME="/home/oracle"
export LANG="no_NO"

I'm not sure if all of these are necessary, but I took no change, and it works now :)
up
0
lffranco *at* dco dot pemex dot com
10 years ago
This took me a lot of time to solve, so I'm placing it here for my future reference, and for somebody who finds it useful. I don't know if it will work on your environment, this is what I have:

* Windoze Advanced Server 2003
* IIS 6
* Oracle 8.1.7

So how I configured the whole thing? First do whatever the standard PHP configuration says... it won't work, anyway... but it will help. I installed PHP on C:\PHP; Oracle Home is in E:\Oracle\ora817.

* Install Oracle 8 client. NOTE: You must use an Oracle 8 client, I used an Oracle 9 client and for some reason (dll binding I guess), it didn't work

* Copy $ORACLE_HOME/bin/cli.dll into $WINDOWS/System32

* Modify your SQLNET.ORA file and change the line:
[code]
SQLNET.AUTHENTICATION_SERVICES= (NTS)
[/code]

by this one:

[code]
SQLNET.AUTHENTICATION_SERVICES= (NONE)
[/code]

I dunno WTF NTS is, so if somebody sends me an eMail and explain, I'll be thankful. But if you don't do this you'll get an ORA-12560 error.

And that's it for Oracle. Now, the IIS configuration:

* Open your IIS Administrator and "Web Service Extensions", add a new extension as follows:
** Extension Name: PHP
** Required Files (ADD): C:\php\extensions\php_oci8.dll; c:\php\sapi\php4isapi.dll; c:\WINDOWS\system32\oci.dll
** Check "Set Extension Status as Allowed"

Now you can use your ocli* functions, or better yet, use PEAR::DB functions which was my ultimate goal, with PEAR::DB you can forget about declaring ORACLE_HOME, ORACLE_SID and all that kind of things. Just use:

<?php
$dsn
= "oci8://scott:tiger@example"
$db = DB::Connect($dsn);
?>
up
0
aleigh at tessier dot com
10 years ago
Warning: ocilogon(): _oci_open_session: OCIHandleAlloc OCI_HTYPE_SVCCTX: OCI_INVALID_HANDLE can also be caused by running the webserver with an ORACLE_HOME of a (radically?) different version than PHP was linked against.

I experienced this when I accidently used an Oracle 8 ORACLE_HOME for a PHP that was linked against Oracle 9.
up
0
aliquis at die dot spammers dot die dot link-net dot org
11 years ago
I've had all kinds of errors with RedHat9(yuck), PHP 4.3.4RC1 and Oracle enterprice server 9.2. For some time I thought that --with-oci8 wouldn't work with Oracle9 but that wasn't the case, the solution was many steps.

1) install oracle, might require some tricks, on RedHat9 I had to put this in my .bashrc:
export ORACLE_BASE=/opt/ora9
export ORACLE_HOME=$ORACLE_BASE/product/9.2
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=netadmdb
export ORACLE_TERM=vt100
export LD_ASSUME_KERNEL=2.4.1
export THREADS_FLAG=native
export LD_LIBRARY_PATH=$ORACLE_BASE/product/9.2/lib:$LD_LIBRARY_PATH

2) compile php, use --with-oci8

3) Make an init-script for the oracle9 database server, as default the TNS listener doesn't run so add that on aswell, example:
#!/bin/bash
export ORACLE_HOME=/opt/ora9/product/9.2
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=netadmdb
export DISPLAY=:0
oracle_user=oracle
export oracle_user
case $1 in
start)
su - "$oracle_user"<<EOO
sqlplus /nolog<<EOS
connect / as sysdba
startup
EOS
/opt/ora9/product/9.2/bin/lsnrctl start
EOO
;;
stop)
su - "$oracle_user"<<EOO
/opt/ora9/product/9.2/bin/lsnrctl stop
sqlplus /nolog<<EOS
connect / as sysdba
shutdown immediate
EOS
EOO
;;
*)
echo "Usage: ora9 [start|stop]"
;;
esac

4) Configure Apache. For some reason it requires some tweaking with environment variables, in the begining I put those in the PHP-script with putenv, later in the httpd.conf with SetEnv and the mod_env module. But I was told to not do that and instead set them in the init script for Apache. So I copied apachectl to /etc/init.d and edited envvars in $APACHE_PATH/bin. First I added all kinds of env variables until I got it to work, and then I removed them one at a time and came to the following minimal configuration:
LD_LIBRARY_PATH="/usr/local/apache2/lib:$LD_LIBRARY_PATH"
ORACLE_HOME=/opt/ora9/product/9.2
LANG=sv_SE
export LD_LIBRARY_PATH ORACLE_HOME LANG

Earlier I had added NLS_LANG and TNS_ADMIN above those mentioned above (point 1), but it seems those aren't needed really. So no need for TWO_TASK or ORACLE_SID, only needed one is ORACLE_HOME and if you get missing/invalid option for your OCILogon set LANG to something else like I did. Someone earlier said it might have to do with UTF8.

So if you are sure lsncrtl are started and that you have the correct env-variables set in your $APACHE_PATH/bin/envvars you can just use something like:

$iDBConn=OCILogon("user","pass","netadmdb");

in your PHP-script and it should work.
Hope this helps someone.
up
0
john at john-warner dot com
11 years ago
In addition to the earlier posts here is a further explaination;

Problem: Regular and Remote authentication does not work using Windows 2000 + PHP and Oracle 8i, 9i.

Secondary Issue if using Oracle 9.2.0.1
     When using Oracle 9.2.0.1 the Error structure returned by Oracle is different than expected by PHP. As a result there will be no legible error message other than the following;
     Warning: _oci_open_server: in ...

Using Oracle 9.0.1.1 the error message returned is any of the following depending on your situation;
    
Warning: _oci_open_server: ORA-12638: Credential retrieval failed in ...
Warning: _oci_open_server: ORA-12154: TNS:could not resolve service name in ...
Warning: _oci_open_server: ORA-12505: TNS:listener could not resolve SID given in connect descriptor in ...
    
Resolution:
In order to get this to work properly you need to do the following;
In reference to ORA-12638: Credential retrieval failed in ...
you need to edit your sqlnet.ora file and change the
SQLNET.AUTHENTICATION_SERVICES = (NTS) to
SQLNET.AUTHENTICATION_SERVICES = (NONE)
The reason is that using NTS validation on a Windows 2000 machine essentially means Kerberos.
Using (NONE) will tell oracle not to expect kerberos "Credentials" as a means of validation. In turn it will use the oracle authentication for a database user.

In reference to ORA-12154 and ORA-12505 you need to do the following;
In your php code you are using to connect you need to copy the section in tnsnames.ora
into a variable.
For example;
<?php
putenv
("ORACLE_SID=TESTDB");
//putenv("ORACLE_HOME=/oracle/ora90");
//putenv("TNS_ADMIN=/oracle/ora90/network/admin");
$username = "scott";
$passwd = "tiger";
$db="(DESCRIPTION=
           (ADDRESS_LIST=
             (ADDRESS=(PROTOCOL=TCP)
               (HOST=yourTargetMachine)(PORT=1521)
             )
           )
             (CONNECT_DATA=(SERVICE_NAME=TESTDB))
      )"
;
$conn = OCILogon($username,$passwd,$db);
if (!
$conn)
{
    echo
"Connection failed";
    echo
"Error Message: [" . OCIError($conn) . "]";
    exit;
}
else
{
    echo
"Connected!";
}
...
?>
I left the ORACLE_HOME and TNS_ADMIN putenv lines commented out and your need for them depends on which web server you are using. If you are using Apache, you may need both.
If you are using Microsoft IIS you may need ORACLE_HOME. Putting it in can't hurt and it appears PHP may read them if they are there but either way you should be working at this
point.

Live long and prosper.
up
0
i990712 at dei dot isep dot ipp dot pt
13 years ago
For those of you who are having Oracle errors: ORA-12154 or ORA-12505 or ORA-01005 do the folowing:

The folowing precedures have been tested when connecting to a HP UX with Oracle 7.x using of couse the OCI8 as the client interface.

Add those lines to the web server config files or set and export those ones before the web server starts.

On Apache add these lines to httpd.conf:

SetEnv ORACLE_HOME /usr/local/oracle
SetEnv ORACLE_SID <sid>
SetEnv LD_LIBRARY_PATH /usr/local/oracle/lib
SetEnv TNS_ADMIN /usr/local/oracle/tnsnames.ora
SetEnv TWO_TASK /usr/local/oracle/tnsnames.ora
SetEnv NLS_LANG  English_America.WE8ISO8859P1
SetEnv ORACLE_BASE /usr/local

When calling the OCILogon do this:

$db = "  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP) (HOST =server_ip_or_dns_name)(PORT = 1521))
    (CONNECT_DATA= (SID = _sid_))
    )";

The previous definition is a copy of the service definition that is stored in the tnsnames.ora file.

Next, call the OCILogon function using the folowing format:

OCILogon("user/password","password", $db);

To avoid ORA-01005 error, set the NLS_LANG environment variable to English_America.WE8ISO8859P1 ( some other values may work...but we have found that this one works for us )

To avoid ORA-12154 and ORA-12505, use the service definition as the OCILogon third parameter.

I'd like to thanks to a friend of mine a.k.a Rosa for the user/password tip.

Regards
Miguel Carvalho
up
0
fsegtrop at estiem dot org
13 years ago
When using PHP4 in CGI-mode with Windows NT or Windows 2000 with IIS or Apache, make sure that the TNSNAMES.ORA and the SQLNET.ORA do not contain DOS/Windows CR/LF line endings.<br> Instead, they must have UNIX (only LF) endings. Otherwise, you will get an ORA-12154 error (TNS cannot resolve service name) when connecting to a remote database.<br>
This all does not matter if you use the ISAPI mode.

Frank
up
0
Marinne at ilovechocolate dot com
13 years ago
One simple but useful note:check whether your TNS Listener is running! By default, it's not started automatically when an Oracle instance is started. Login as oracle then type :

lsnrctl START

After it's started, I can sucessfully run the sample code on this page! I used to got ora-12514 error before doing this.
up
0
bluei at phpworld dot org
13 years ago
check your tnsnames.ora permission.

ex)
ORACLE_HOME = /home/oracle/oracle

chmod 755 /home/oracle/oracle/network/admin -R

Yahoo!!!!!! I solved it!!!
up
-1
P dot D dot Mallinson at liv dot ac dot uk
3 years ago
Platform: Solaris 10, Apache 2.2, Oracle 11 client

It is well known that the Oracle Instant Client 11g libraries conflict with the OpenLDAP ones. 

If features of the 11g client libraries are vital (e.g. needing SQLNET timeouts to work and/or needing to get Oracle service names from directory servers via LDAP - both required in my organisation) then in order to achieve a working oci8 and OpenLDAP setup it is necessary to preload the instant client library in the Apache startup script - e.g.:

# Setup for Oracle 11 instant client
ORACLE_HOME=/usr/local/oracle/instantclient_11_2
export ORACLE_HOME
#
LD_LIBRARY_PATH=/usr/local/oracle/instantclient_11_2:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
#
LD_PRELOAD=/usr/local/oracle/instantclient_11_2/libclntsh.so.11.1
export LD_PRELOAD
up
-1
buswash at gmail dot com
9 years ago
PHP 5.0.3 + Solaris 9 (UltraSPARC) + Apache 2.0.51 + Oracle 10g Instant Client 10.1.0.3

Thanks to Jakob's patch I got this combination working.  Here are some things that helped me:

1. After getting this:
ld: fatal: file /opt/oracle/instantclient/libclntsh.so: wrong ELF class: ELFCLASS64

I realized that PHP is a 32-bit application and that all 3rd-party libraries need to be 32-bit as well.  You need to download the 32-bit version of Instant Client (basic + sdk), even if you are running the 64-bit Solaris OS.

2. My patch command syntax was a little different:
patch -p0 -i php5_ociclient.patch config.m4

Thanks again to Jakob for porting the patch over to PHP 5.

Marc
up
-1
Mark at catalyst dot net dot nzed
10 years ago
ReCompiling PHP4 to have oracle 8 support (oci8) on Debian Linux, using the Oracle 10g client libraries. Log in as root.

PACKAGES REQUIRED:
php4-dev
php4 (source files)
php4 module (might not be required, but it's what i had installed at the time)

OTHER PACKAGE REQUIREMENTS:
Oracle Client Libraries (i used Oracle 10g Server, but you should be able to use, as has been previously said, any set of the oracle client libraries from 8i onwards).
* make sure this is installed before recompiling php4.

ENVIRONMENT REQUIREMENTS:
- export ORACLE_HOME=[where u installed the oracle client]
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
- export LD_PRELOAD=libclntsh.so.10.1 (the version number at the end will correspond to the oracle version you previously installed. in my case, 10g is 10.1).
- vi /etc/ld.so.conf and add $ORACLE_HOME/lib to the list of paths.
then * run ldconfig to reload those changes to the system * (p.s. make sure it's the full path, and not using any environment variables. e.g. /u01/app/oracle/product/10gRDBMS is my ORACLE_HOME).

STEPS:
- cd /usr/src/[PHP4 Version]
in my case, [PHP4 Version] = php4-4.3.8, so path was
/usr/src/php4-4.3.8

- vi debian/rules
these are the default compilation rules for php4. Find section labeled COMMON_CONFIG = [...] and add --with-oci8 (it should be near the top of the file).

- debchange -i (allows you to edit the change log for the versions of php. btw - you should be in the php4 source code directory). give the version id something obviously unique. don't forget to add a comment.

when all is in readyness, then you should be able to go debian/rules binary to build the debian packages required.
the deb packages are built into the /usr/src directory. and depending on the default compilation options u choose, there should be a few. find the deb package that corresponds to the main php4 module (php4_4.3.8-4.mark.1_i386.deb for me), and run dpkg -i [package name] to install it.

- vi /etc/init.d/apache and add exports for $ORACLE_HOME, $LD_PRELOAD and $LD_LIBRARY_PATH

* don't forget to restart apache /etc/init.d/apache to reload the php4 module. *

IF YOU GET... :
if you get an error saying something about apache cannot load libclntsh.so.10.1, file not found, check the environment variables, for both the user, and in /etc/init.d/apache and also check ld.so.conf to make sure the $ORACLE_HOME/lib path is in there, and has been reloaded (with ldconfig).

editing ld.so.conf was the part that finally got it working for me.
as you should be able to tell, the steps are pretty much the same as for all oracle versions 8i onwards, and all linux OS's. but with a few debian specific paths and commands thrown in.
up
-1
lomax at arizona edu
11 years ago
Can't compile php with Oracle 9i and apache on Solaris8?
Sun 280R

Using some of the tips below I had to add this:
(static build)

#!/bin/tcsh
setenv LDFLAGS -L$ORACLE_HOME/lib32

cd php-4.x.x/
./configure --with-oci8=$ORACLE_HOME --with-apache=/path/to/apache_src ..etc
make
make intsall

cd apache_src
(make sure environment variable is still set)
./configure  "--prefix=/usr/apache" "--enable-module=so" \
"--activate-module=src/modules/php4/libphp4.a"  ...etc
make
make install

Having the gcc compilier build php against oracle 32 bit libraries was the key, but without setting LDFLAGS the compiler defaults to using the 64-bit oracle libraries which cause the famous
"...wrong ELF class: ELFCLASS64.." on startup.

The only diffenece here was I didn't have to do play musical directories for it to work. The below post was instrumental in helping me to get this fixed. Thanks to "lore_giver at lycos dot co dot uk"
up
-1
ddc at portalframework.com
12 years ago
Sometimes Oracle doesn't cleanup shadow processes when accessed from PHP. To avoid that, check your
$ORACLE_HOME/network/admin/tnsnames.ora file in your Oracle Client directory and remove the (SERVER=DEDICATED) token if is set.

To let Oracle delete shadow process on timeouts, add the following line in your $ORACLE_HOME/network/admin/sqlnet.ora
found in your ORACLE Server directory:

SQLNET.EXPIRE_TIME=n

Where 'n' is the number of minutes to let connection idle befor shutting them out.
To Top