Oci_connect () only works from the command line

Ok, so I have this terrible problem with oci, apache, php and suse. Firstly, versions:

PHP 5.3.15 (cli)
Apache/2.2.22 (Linux/SUSE)
OCI8 1.4.9
SUSE 12.2 32 bit
Oracle client 10.2.0.4

Problem

I have a really simple php file:

<?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    oci_connect('user', 'passwd', 'host/sid');
?>

When I run it from the command line, it does a fine:

machine:~ # php oci.php
machine:~ #

But when I run it in a browser, it gives me:

Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories

Apache configuration

I have been struggling with this issue for a long time, and I'm sure my Apache configuration is correct.

I export all the required variables until when any apache process is running - I added

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/oracle/home/lib; export LD_LIBRARY_PATH
ORACLE_HOME=/path/to/oracle/home; export ORACLE_HOME
TNS_ADMIN=/path/to/oracle/home/network/admin; export TNS_ADMIN
NLS_LANG=POLISH_POLAND.EE8MSWIN1250; export NLS_LANG

at the beginning of the /etc/init.d/apache2script (I am running apache with /etc/init.d/apache2 start).

Apache runs on a user wwwrunwho is in oinstalland dbagroups:

machine:~ # cat /etc/apache2/uid.conf
User wwwrun
Group www
machine:~ # id wwwrun
uid=30(wwwrun) gid=8(www) groups=8(www),113(oinstall),114(dba)
machine:~ # l $ORACLE_HOME
total 216
drwxr-xr-x 48 oracle oinstall 4096 Jan 25 17:07 ./
drwxrwxr-x  3 oracle oinstall 4096 Jan 25 17:01 ../
...
machine:~ #

Possible problem

- Environment phpinfo(); - ? , ? - ? , SELinux , , .

?

!

+6
4

! ( Oracle Environment) ken_yap .

Apache Environment, /etc/sysconfig/apache2: LD_LIBRARY_PATH=/path/to/oracle/lib.

+6

( root-) php:

putenv("ORACLE_HOME=/opt/app/oracle/product/11.2.0/db_1");
putenv("LD_LIBRARY_PATH=/opt/app/oracle/product/11.2.0/db_1/lib:/lib:/usr/lib");

+4

For Debian users - edit the file

/etc/apache2/envvars

at the end of the file, add a link to your OCI library - for example.

export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2
0
source

Another approach to Centos 7 with nginx

$ sudo vim /etc/ld.so.conf.d/oracle-instantclient.conf

// Add path to oracle client lib, the XX is the version, ex: /usr/lib/oracle/XX/client64/lib 

$ sudo ldconfig
$ sudo service php-fpm restart

Done!

0
source

All Articles