I am trying to setup php/nginx to connect to an oracle database.
Everything is on a single server (testing)
I installed nginx and set it up just fine it works. I setup php and php-fpm and that works fine (tested some php stuff)
I installed oci8 module using pecl install oci8 and provided the path to my oracle_home, it compiled just fine.
but I Can't connect to a database.
I tried multiple scripts.
I am pretty new to oracle.
the www-error log for php-fpm says to check my oracle_home and ld library path. I set both in my php script as a test and still fails.
any ideas?
<?php
PutEnv("ORACLE_SID=orcl");
PutEnv("ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/");
PutEnv("TNS_ADMIN=/opt/app/oracle/product/11.2.0/dbhome_1/network/admin");
PutEnv("LD_LIBRARY_PATH=/opt/app/oracle/product/11.2.0/dbhome_1/lib");
$c = oci_connect("testuser", "testpassword", "127.0.0.1");
if (!$c) {
echo "Unable to connect: " . var_dump( oci_error() );
die();
}
ETCETC
from the error log:
[10-Dec-2010 17:25:58] PHP Warning: 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 in /usr/share/nginx/html/orcl2.php on line 6
EDIT: I added the nginx user to the oinstall group for testing purposes and now I do get better error messages so I am getting further.
the error now is:
array(4) { ["code"]=> int(12504) ["message"]=> string(70) "ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA" ["offset"]=> int(0) ["sqltext"]=> string(0) "" } Unable to connect:
EDIT2: After doing the following I am now able to use the sqlplus command to connect with my test user but php still fails.
SQL> alter system set LOCAL_LISTENER='10.99.101.2' scope=both;
SQL> alter system register;
SQL> alter system set SERVICE_NAMES='10.99.101.2' scope=both;
EDIT3: if I use php command line to run my test script it works fine so something is wrong with Nginx/env variables for said nginx.
EDIT4: Listener.ora:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = orcl)
(ORACLE_HOME = /opt/app/oracle/product/11.2.0/dbhome_1/)
(PROGRAM = extproc)
)
(SID_DESC=
(GLOBAL_DBNAME=orcl)
(ORACLE_HOME=/opt/app/oracle/product/11.2.0/dbhome_1/)
(SID_NAME=orcl)
)
)
SUBSCRIBE_FOR_NODE_DOWN_EVENT_LISTENER=OFF
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.99.101.2)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /opt/app/oracle
tnsnames.ora:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.99.101.2)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)
sqlnet.ora
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
ADR_BASE = /opt/app/oracle