我正在使用即时 oracle 客户端 11.2、php 5.5.16,它们是从具有以下配置参数的源代码编译的:
'./configure' '--enable-fpm' '--enable-bcmath' '--with-bz2' '--enable-calendar' '--with-curl' '--enable -dba' '--enable-exif' '--enable-ftp' '--with-gd' '--with-gettext' '--with-kerberos' '--enable-mbstring' '--with- mcrypt' '--with-openssl' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-wddx' '--enable-zip ' '--with-zlib' '--with-xsl' '--with-mysql' '--with-mysqli' '--with-pgsql' '--with-pdo-mysql' '--with- pdo-pgsql' '--with-oci8' '--with-pdo-oci'
在我之前的配置中,我使用 apache2(--with-apxs2=/usr/bin/apxs2
而不是 --enable-fpm
)与 oracle 和 oci8 。我的数据源名称是:“oci:dbname=//IP:1521/SID;charset=UTF8”
。
它运行得很好。
今天我想将此服务器配置从 apache 移动到 nginx 和 fpm。一切工作正常,除了在连接时,PDO 抛出:
OCIEnvNlsCreate:检查字符集是否有效以及 PHP 是否有权访问 Oracle 库和 NLS 数据
除了 php-fpm 处理 php 而不是 apxs 之外,我得到了完全相同的配置。
如果我删除 charset=UTF8
部分,它可以工作,但显然我遇到了字符集错误。我已将 env[NLS_LANG]=FRENCH_FRANCE.UTF8
环境变量添加到我的 php_fpm.conf
中,但没有成功。
我该怎么做才能使 nginx/php-fpm 配置正常工作?
最佳答案
再次阅读 oci8 installation php page 上的评论我已经解决了这个问题。
事实是,即使 oracle php docs 中提到了这一点,在php_fpm.conf
中设置环境变量不起作用!
你必须:
将 Oracle 特定配置文件写入
vim/etc/profile.d/oracle.sh
#!/bin/bash ORACLE_HOME=/usr/lib/oracle/11.2/client64 C_INCLUDE_PATH=/usr/include/oracle/11.2/client64 LD_LIBRARY_PATH=$ORACLE_HOME/lib #remember this is the client NLS_LANG not the server one NLS_LANG=FRENCH_FRANCE.UTF8 export ORACLE_HOME LD_LIBRARY_PATH NLS_LANG
将此添加到
/etc/init.d/php-fpm
。/etc/profile.d/oracle.sh
关于Oracle PDO OCI 字符集失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25649581/