2

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
1
  • According to your edits, the error should come either from the sqlnet.ora (sqlnet layer tuning file) listener.ora (oracle listener configuration file) or the tnsnames.ora (oracle client configuration file). Could you post the thee of them?
    – Benoit
    Dec 13, 2010 at 15:35

1 Answer 1

1

Your connection string is incorrect. Are you sure that "orcl" is the SID of your database and not the service name or the name on an entry in your tnsnames.ora (should be in $TNS_ADMIN/)?

What are the result of the following commands?

$ORACLE_HOME/bin/tnsping orcl
$ORACLE_HOME/bin/lsnrctl status

Can you connect to your database using the following command?

$ORACLE_HOME/bin/sqlplus "testuser"/"testpassword"@orcl
1
  • Hi Benoit, Thanks for the reply. If I do a tnsping it says ok: ttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.99.101.2)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = 10.99.101.2))) OK (0 msec) The status of the listener is ok as well and finally the sqlplus command failed with the same error message, if I try your command but with @10.99.101.2 that fails as well same error message. Thanks again I do appreciate it!
    – Luma
    Dec 11, 2010 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .