oci_connect() works only from command line
Solution 1
Problem solved! Thanks to these (Setting the Oracle Environment section) instructions and ken_yap's answer to this thread.
To put variables in Apache's Environment section you just have to add them in /etc/sysconfig/apache2
file: LD_LIBRARY_PATH=/path/to/oracle/lib
.
Solution 2
Another solution ( that do not need root access ) is to add this lines in the php page:
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");
Regards
maialithar
I'm a student, currently working on my master's thesis. I also work as a helpdesk support in medium-size company. Well, helpdesk is not all that I do. Sometimes I have to analyze some oracle db issues, write PL/SQL code, some php/js webpage or a program in java. The main reason for me to contribute here is to learn new things. I visit SO webpage very often, I want to finally thank all those awesome posts that helped me in the past! Thank you all contributors!
Updated on June 22, 2022Comments
-
maialithar almost 2 years
OK, so I have this terrible problem with oci, apache, php and suse. First off, 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 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 command line it executes fine:
machine:~ # php oci.php machine:~ #
But when i run it in 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've been struggling with this issue for some time now and I'm pretty sure my apache configuration is correct.
I export all required variables before any apache process is started - 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
/etc/init.d/apache2
script (I start apache by/etc/init.d/apache2 start
).Apache runs from
wwwrun
user, who is inoinstall
anddba
groups: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
I don't have any environmental variables in
Environment
section inphpinfo();
output - could this be the problem? If yes, how can I fix this? Is it some kind of security issue? I've read about problems like that with SELinux enabled, but I don't have it, my firewall is off.Solution?
Any help would be greatly appreciated!
-
cartbeforehorse over 8 yearsin CentOS 7, the file is called
/etc/sysconfig/httpd
-
Christopher Jones over 5 yearsIt's generally a bad idea to add environment variables to runtime code - they can often be ignored because the code is run after process or module initialization