放在/var/www/html/condb.php文件中的PHP代码下面。
$conn = @oci_connect('sysdba', 'password', 'localhost/ORCL');
if (!$conn) {
die("Database Connection Error");
我正在将RHEL 7.2与在我的64位计算机上安装的Oracle 12c一起使用。
我按照以下步骤安装了OCI:
1.yum安装php-devel
2.pecl install oci8-2.0.10(提示输入时提供了我的$ ORACLE_HOME路径)
3.在/etc/php.ini
中添加了 extension = oci8.so 条目。
4.service httpd restart
输入时,我会看到 oci8 :
root@oracle# php -m
现在,我可以在浏览器中查看放在/ var / www / html /中的静态网页了。但是我无法通过上述脚本连接到Oracle DB。
如果有人可以帮助我,那将有很大的帮助。
如果缺少任何内容,请指导在DB或php.ini文件中进行配置。 谢谢。
编辑1:错误日志
[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.
编辑2:我已尝试在谷歌搜索时添加上述错误:
在此路径下添加/ 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
我也纠正了/ etc / hosts来克服httpd错误
127.0.0.1 localhost.localdomain localhost
<myip_here> oracle_12C.localdomain oracle_12C
这些更改之后,我重新启动了“ service httpd restart”。
现在,如果我运行放在/var/www/html/condb.php文件中的PHP代码,则可以在error_log中看到以下内容。
PHP Warning: oci_connect(): ORA-12541: TNS:no listener
我的听众听的很好。请在下面检查并纠正我。
[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
编辑3 :
我更改了代码,如下所示:
$conn = oci_connect('sysdba', 'password', 'localhost:1539/ORCL');
现在error_log显示用户名/密码似乎很好,我使用它通过sys /作为sysdba命令进行连接。
PHP Warning: oci_connect(): ORA-01017: invalid username/password; logon denied
编辑4 :
正如一些视频所建议的那样,listener.ora现在看起来像:
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)
)
)
仍然得到相同的“ NO LISTENER”。