ssh2_connect之后PHP与数据库的连接

时间:2015-11-02 15:40:12

标签: php postgresql ssh remote-access

我有一个网站,我正在尝试与位于我的个人服务器(CentOS 7)上的PostgreSQL数据库进行通信。

我已采取以下步骤

  • 转发我服务器上的ssh端口(禁用密码验证后)
  • 生成了ssh密钥并将它们放在Web服务器上
  • 在网络服务器上设置SSH2.so库
  • 创建了用于建立连接的php脚本

这些都工作正常,我的脚本能够连接到ssh服务器

<?php

ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);

$connection = ssh2_connect('xxx.xx.xx.xx', 22);

if (ssh2_auth_pubkey_file($connection, 'usname',
                      './ssh_key.pub',
                      './ssh_key', 'psword')) {

    echo "Public Key Authentication Successful\n";

} else {

    die('Public Key Authentication Failed');

}

?>

所有这一切都有效,但我很难连接到我已建立连接的服务器上的数据库,是否有不同的方式连接到使用ssh连接的数据库?

0 个答案:

没有答案
相关问题