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?

   $c = oci_connect("testuser", "testpassword", "");
   if (!$c) {
     echo "Unable to connect: " . var_dump( oci_error() );


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='' scope=both;
SQL> alter system register;

SQL> alter system set SERVICE_NAMES='' 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_DESC =
     (SID_NAME = orcl)
     (ORACLE_HOME = /opt/app/oracle/product/11.2.0/dbhome_1/)
     (PROGRAM = extproc)
      (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521))

ADR_BASE_LISTENER = /opt/app/oracle

    (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521))


ADR_BASE = /opt/app/oracle
  • 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 '10 at 15:35

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
  • Hi Benoit, Thanks for the reply. If I do a tnsping it says ok: ttempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = 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 @ that fails as well same error message. Thanks again I do appreciate it! – Luma Dec 11 '10 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.