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'.