oci_connect()仅从命令行工作 [英] oci_connect() works only from command line
问题描述
好的,所以我在oci,apache,php和suse中遇到了这个可怕的问题.首先,版本:
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
问题
我有一个非常简单的php文件:
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配置
我已经为这个问题苦苦挣扎了一段时间了,我很确定我的apache配置是正确的.
Apache configuration
I've been struggling with this issue for some time now and I'm pretty sure my apache configuration is correct.
我在所有apache进程开始前导出所有必需的变量-我添加了
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
在/etc/init.d/apache2
脚本的开头(我从/etc/init.d/apache2 start
开始apache).
at the beginning of /etc/init.d/apache2
script (I start apache by /etc/init.d/apache2 start
).
Apache从oinstall
和dba
组中的wwwrun
用户运行:
Apache runs from wwwrun
user, who is in oinstall
and dba
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:~ #
可能的问题
在phpinfo();
输出的Environment
部分中没有任何环境变量-这可能是问题吗?如果是,我该如何解决?这是某种安全问题吗?我已经阅读了有关启用SELinux的问题,但我没有,防火墙已关闭.
Possible problem
I don't have any environmental variables in Environment
section in phpinfo();
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.
任何帮助将不胜感激!
推荐答案
问题已解决!感谢这些(设置Oracle环境部分)说明以及ken_yap对
Problem solved! Thanks to these (Setting the Oracle Environment section) instructions and ken_yap's answer to this thread.
要将变量放在Apache的 Environment 部分中,只需将它们添加到/etc/sysconfig/apache2
文件:LD_LIBRARY_PATH=/path/to/oracle/lib
中.
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
.
这篇关于oci_connect()仅从命令行工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!