1

Below PHP code placed in /var/www/html/condb.php file.

$conn = @oci_connect('sysdba', 'password', 'localhost/ORCL');
if (!$conn) {
die("Database Connection Error");

I'm using RHEL 7.2 with Oracle 12c installed on my machine-64bit.

I followed below steps for installing OCI:

1.yum install php-devel
2.pecl install oci8-2.0.10 (Have provided my $ORACLE_HOME path when prompted for input)
3.Added extension=oci8.so entry in /etc/php.ini
4.service httpd restart

I could see oci8 when typed:

root@oracle# php -m

Now, I am able to view static web pages placed in /var/www/html/ in my browser. But I'm unable to connect to Oracle DB through above script.

It would be of great help if anyone could help me out.

Please guide if anything is missing to configure in DB or php.ini file. Thanks.

EDIT 1: Error Logs

[Sun Nov 25 18:15:37.769964 2018] [mpm_prefork:notice] [pid 14650] 
AH00170: caught SIGWINCH, shutting down gracefully
[Sun Nov 25 18:15:45.847496 2018] [suexec:notice] [pid 2853] AH01232: 
suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the servers fully 
qualified domain name, using fe80::72b8:d28b:5663:72bb. Set the 
'ServerName' directive globally to suppress this message
[Sun Nov 25 18:15:45.879946 2018] [auth_digest:notice] [pid 2853] 
AH01757: generating secret for digest authentication ...
[Sun Nov 25 18:15:45.880445 2018] [lbmethod_heartbeat:notice] [pid 
2853] AH02282: No slotmem from mod_heartmonitor
[Sun Nov 25 18:15:46.064159 2018] [mpm_prefork:notice] [pid 2853] 
AH00163: Apache/2.4.6 (Red Hat Enterprise Linux) PHP/5.4.16 configured 
-- resuming normal operations
[Sun Nov 25 18:15:46.064191 2018] [core:notice] [pid 2853] AH00094: 
Command line: '/usr/sbin/httpd -D FOREGROUND'
[Sun Nov 25 18:15:49.588372 2018] [:error] [pid 3395] [client 
::1:49329] PHP Warning:  oci_connect(): Error while trying to retrieve 
text for error ORA-01804\n in /var/www/html/condb.php on line 8
[Sun Nov 25 18:15:54.600169 2018] [:error] [pid 3395] [client 
::1:49329] 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 /var/www/html/condb.php on l.

EDIT 2: I've tried adding this upon googling for above errors:

Added below in this path /etc/sysconfig/httpd

ORACLE_HOME=/oracle/product/12.1.0/db_1
LD_LIBRARY_PATH = /oracle/product/12.1.0/db_1/lib:/lib:/usr/lib 
TNS_ADMIN=/oracle/product/12.1.0/db_1/network/admin 
ORACLE_SID=db1

I have corrected my /etc/hosts as well to overcome httpd error

127.0.0.1    localhost.localdomain  localhost
<myip_here>   oracle_12C.localdomain  oracle_12C

After these changes, i have restarted 'service httpd restart'.

Now, I'm able to see below in error_log, if I run PHP code placed in /var/www/html/condb.php file.

PHP Warning:  oci_connect(): ORA-12541: TNS:no listener

My listener is perfectly listening. Please check below and correct me.

[oracle@oracle-12c admin]$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 27-NOV-2018 18:10:28

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.143.244.1)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date                27-NOV-2018 16:58:40
Uptime                    0 days 1 hr. 11 min. 47 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File         /oracle/diag/tnslsnr/oracle-12c/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.143.244.1)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=oracle-12c)(PORT=5500))(Security=(my_wallet_directory=/oracle/admin/orcl/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "db1", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "db1", status READY, has 1 handler(s) for this service...
Service "pdborcl" has 1 instance(s).
  Instance "db1", status READY, has 1 handler(s) for this service...
The command completed successfully

EDIT 3 :

I have changed my code as below:

$conn = oci_connect('sysdba', 'password', 'localhost:1539/ORCL');

And now error_log shows as though username/password are fine and i use same to connect by sys / as sysdba command.

PHP Warning:  oci_connect(): ORA-01017: invalid username/password; logon denied 

EDIT 4:
As some video suggested, listener.ora now looks like:

 LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.143.244.1)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

#Added below part

SID_LIST_LISTENER =
(SID_LIST=
        ( SID_DESC =
                (SID_NAME =db1)
                (ORACLE_HOME = /oracle/product/12.1.0/db_1)
        )
)

Still get the same 'NO LISTENER'.

GSK
  • 11
  • 3
  • for a start remove the @ infront of the oci_connect. Does it throw and errors? – atoms Nov 24 '18 at 20:29
  • Thanks for the suggestion, but still I'm unable to connect after removing @. – GSK Nov 25 '18 at 03:41
  • Have you checked php error logs? There will be an error message somewhere, if configured – atoms Nov 25 '18 at 10:23
  • Edited to display error logs /var/log/httpd/error_log. Please suggest to overcome this. – GSK Nov 25 '18 at 12:54
  • good question,e would give this more rep if I could. Are you certain localhost:1539/ORCL is the right endpoint? Are there restrictions in oracle that prevent anything that shell access? I would look into the new error message a bit more. Maybe this will help https://stackoverflow.com/questions/14646007/oci-connect-connection-failed – atoms Nov 25 '18 at 21:25
  • or https://stackoverflow.com/questions/14646007/oci-connect-connection-failed https://stackoverflow.com/questions/14476875/ – atoms Nov 25 '18 at 21:32
  • Again i see 'PHP Warning: oci_connect(): ORA-12541: TNS:no listener' irrespective of including port number :1539. Now, there is no error saying invalid username/password. No changes were done to any configs till now, yet I see this weird behaviour. Request your help in debugging. – GSK Nov 26 '18 at 14:07
  • Im unsure on the specifics of configuring oci. There's some very good information in the two links provided. You could try the port 5500? Other than that you are using user sysdba in your php script but connecting in the shell using oracle, are you sure you have the correct creds? Assuming the error message is acurate, it rules out the possibility of a routing issue with php to the service. – atoms Nov 26 '18 at 20:16
  • I have tried using user as "SYS" in the script with/without port 5500 which results in throwing the same error. I have added the script (see EDIT 4), still, the issue persists. I did not get when you said 'connecting shell using Oracle'? Kindly elaborate. – GSK Nov 27 '18 at 11:42
  • whats about PDO? – Doğan Uçar Nov 27 '18 at 14:25
  • Hi Dogano, I thank you for suggesting. I have run 'yum install php-pdo'. I have Oracle DB on my machine. Now, How do I install PHP PDO for Oracle DB on RHEL 7.2? What are the necessary changes to do in php.ini? Pls suggest. – GSK Nov 27 '18 at 15:22

0 Answers0