duanpacan2583 2015-02-16 17:55
浏览 64
已采纳

Vagrant Oracle ORA-12541:TNS:/var/www/core/db.class.php中没有听众

I've finished configuring a Vagrant box with oracle 11G.

I've tested the connection using SqlDeveloper from my local MAC machine and all seems fine (ssm_android -> localhost 1521 xe).

What I really need is to connect to this Oracle DB through PHP.

Here's my Vagrant config for the oracle machine (I added some relevant info below):

vagrant@oracle:/u01/app/oracle/product/11.2.0/xe/network/admin$ echo $ORACLE_HOME 
/u01/app/oracle/product/11.2.0/xe

vagrant@oracle:/u01/app/oracle/product/11.2.0/xe/network/admin$ echo $ORACLE_SID  
XE

vagrant@oracle:/u01/app/oracle/product/11.2.0/xe/network/admin$ vi listener.ora 

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      (ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

vagrant@oracle:/u01/app/oracle/product/11.2.0/xe/network/admin$ vi tnsnames.ora

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

vagrant@oracle:/u01/app/oracle/product/11.2.0/xe/network/admin$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 16-FEB-2015 13:26:37

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date                16-FEB-2015 11:34:27
Uptime                    0 days 1 hr. 52 min. 10 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           XE
Listener Parameter File   /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "XE" has 1 instance(s).
  Instance "XE", status READY, has 1 handler(s) for this service...
Service "XEXDB" has 1 instance(s).
  Instance "XE", status READY, has 1 handler(s) for this service...
The command completed successfully

And here's the error i get in PHP when I try connecting using the following data

user = "ssm_android"
host = "127.0.0.1:1521/XE"
password = "xxxxxxx"
database = "XE"

:

Fatal error: Uncaught exception 'Exception' with message 'Cannot connect to database: ORA-12541: TNS:no listener' in /var/www/core/db.class.php:164 Stack trace: #0 /var/www/core/db.class.php(113): Db->connect('ssm_android', 'NtakmdVSYgsYSNii11...', '127.0.0.1:1521/...') #1 /var/www/index.php(56): Db->__construct() #2 {main} thrown in /var/www/core/db.class.php on line 164

Could be relevant the fact that the machine running the php is another local Vagrant machine mapped to localhost... not sure..

I'd appreciate any insight on this.

Thanks.

  • 写回答

1条回答 默认 最新

  • douye9175 2015-02-19 04:12
    关注

    It seems the whole problem was that both vagrant machines were configured with dynamic ips. Changing vagrant config files to include static ips did the trick.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题