今天一台服务器的环境搭好之后,oci也扩展成功了,在phpinfo界面也显示了。
但是正确的代码确始终联不上oracle数据库,直接报404错误,
贴上代码:
<?php
// Connects to the XE service (i.e. database) on the "localhost" machine
$db = "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.1.1)(PORT = 1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)))";
$conn=oci_connect('1','1',$db);
//$conn=oci_connect('1','1','10.1.1.1/orcl');
if (!$conn) {
$e = oci_error();
print htmlentities($e['message']);
exit;
}else{
echo 'haha,ok';
}
?>
更改代码:
$conn=oci_connect('1','1',$db,'utf8');
然后不404了,但是出现如下报错:
Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system – please check that LD_LIBRARY_PATH includes the directory with Oracle Instant Client
根据错误提示,意思是没有设置LD_LIBRARY_PATH,然后找了很多资料,还是没搞定。。最后没办法,到另一台正常的服务器上phpinfo作了一对比,我日,意外发现少的是 Environment 下面的ORACLE_HOME,然后在php-fpm.conf文件里添加了最后一句,抄他妹,终于好了!!!
[root@localhost oci8-2.0.5]# vi /www/server/php/56/etc/php-fpm.conf
[global]
pid = /www/server/php/56/var/run/php-fpm.pid
error_log = /www/server/php/56/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php-cgi-56.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.status_path = /phpfpm_56_status
pm.max_children = 150
pm.start_servers = 30
pm.min_spare_servers = 30
pm.max_spare_servers = 150
request_terminate_timeout = 100
request_slowlog_timeout = 30
slowlog = var/log/slow.log
env[ORACLE_HOME] = /usr/lib/oracle/10.2.0.5/client64/lib
注意这个地方是加到php的环境里,并不是系统的环境变量,我一直纠结在了系统变量,加在了/etc/profile里,然并卵。只是个人的分享,不知是否适用于他人,仅供参考。