简体   繁体   中英

Warning: oci_connect(): OCIEnvNlsCreate() failed

Error

Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that LD_LIBRARY_PATH includes the directory with Oracle Instant Client libraries in

Warning: oci_connect(): Error while trying to retrieve text for error ORA-01804

apache php oracle install method

1. /etc/profile

##################### oracle oci setting
export LD_LIBRARY_PATH=/usr/lib/oracle/19.6/:$LD_LIBRARY_PATH

2. download oracle 19.6 instantclient download / install

https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
download instantclient-basic-linux.x64-version.zip
download instantclient-sdk-linux.x64-version.zip
download instantclient-sqlplus-linux.x64-version.zip
unzip * 
mv instantclient_19_6/ /usr/lib/oracle/19.6

3. ldconfig set

echo '/usr/lib/oracle/19.6' > /etc/ld.so.conf.d/oracle-instantclient.conf
ldconfig

4. vi /etc/tnsnames.ora

ORA_TEST =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ip_address)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = ip_address)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORA_TEST)
      (SERVER = dedicated)
    )
  )

5. oracle connect test ==> succcess

sqlplus test/test@ORA_TEST 

6. web server install

yum -y install httpd httpd-devel mod_ssl 

7. php install

yum-config-manager --enable remi-php56
yum --enablerepo=remi-php56 -y install php php-devel php-cli php-common php-mbstring php-mcrypt php-xml php-pear php-curl php-pecl-imagick php-oci8 php-soap

8. PHP Warning: PHP Startup: Unable to load dynamic library 'oci8.so'

ln -s /usr/lib/oracle/19.6/libclntsh.so.19.1 /lib64/libclntsh.so.19.1
ln -s /usr/lib/oracle/19.6/libnnz19.so /lib64/libnnz19.so
ln -s /usr/lib/oracle/19.6/libclntshcore.so.19.1 /lib64/libclntshcore.so.19.1

9. phpinfo() oci8 in phpinfo

10. console php test ==> succcess

php -r "oci_connect('test', 'test', 'ORA_TEST');" 

11. web site php code ==> fail

$oracle = oci_connect('test' , 'test', 'ORA_TEST', "AL32UTF8");

Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something wrong with your system - please check that LD_LIBRARY_PATH includes the directory with Oracle Instant Client libraries in

Warning: oci_connect(): Error while trying to retrieve text for error ORA-01804

12. php -v, php -ri oci8 php -v, php --ri oci8

Your web server is not configured correctly to set LD_LIBRARY_PATH for PHP. See this post for a similar example, and make sure you are setting the environment correctly for the web server runtime.

You are setting up a lot of things that don't need setting up. Read the Instant Client installation instructions again.

Let's take a look:

export ORACLE_HOME=/usr/lib/oracle/19.6

Never set ORACLE_HOME when using Oracle Instant Client. It can lead to errors like ORA-1804 or other startup problems.

export TNS_ADMIN=$ORACLE_HOME/network/admin

If you had a simpler install you wouldn't need to set this. See the Instant Client installation instructions.

export LD_LIBRARY_PATH=/usr/lib/oracle/19.6/lib:$ORACLE_HOME/sdk:$LD_LIBRARY_PATH

Use ldconfig as shown in the installation instructions so you don't have to worry about setting LD_LIBRARY_PATH and making sure it passed through to Apache (a common problem with PHP - and one you are probably hitting). And there are no libraries in the sdk directory so that definitely doesn't need to be there.

export DYLD_LIBRARY_PATH=/usr/lib/oracle/19.6/lib:$DYLD_LIBRARY_PATH

This is for macOS, which you are not running

export PATH=$PATH:$ORACLE_HOME:$ORACLE_HOME/bin

export NLS_LANG=AMERICAN_AMERICA.AL32UTF8

These could be useful.

mkdir -p /usr/lib/oracle/19.6/bin /usr/lib/oracle/19.6/lib /usr/lib/oracle/19.6/network/admin

ln -s libclntsh.so.19.6 libclntsh.so

ln -s libocci.so.19.6 libocci.so

[. . . ]

This all seems very convoluted. Why not just move the unzipped directory to somewhere like /opt/oracle/instantclient_19_6 and run ldconfig as shown in the instructions? Then you don't need to make links, directories, copy files etc etc.

You could do worse that look at the install instructions in the PHP Dockerfiles at https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers/oraclelinux7/php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM