douzhi2012 2017-02-02 14:14
浏览 74

通过PHP中的反向SSH Mysql连接

This is my first post here, I hope you can help me.

What I'm triying to do, is connect via reverse SSH to a company' remote server.

COMPANY $ ssh -R 36060:localhost:22 local@x.x.x.x

Then in the local

LOCAL $ ssh company@localhost -p 36060
LOCAL $ mysql -h 127.0.0.1 -u root -p root

Everything is good, the conection works in the terminal, I can see the tables, no problem.

After all this, in the php archive.

<?php
$cnn = mysqli_connect('127.0.0.1','root','root','user_database',33060);
?>

But always send me an error when I try to opened in the browser.

Warning: Packets out of order. Expected 0 received 45. Packet size=4739923 in /opt/lampp/htdocs/test.php on line 2
Warning: mysqli_connect(): MySQL server has gone away in /opt/lampp/htdocs/test.php on line 2

I try to change the config in the "test server", change in LOCAL and COMPANY the max_allowed_packet = 128M in my.cf but nothing works.

If you have any idea, please help :(

EDIT: Problem solved!

SERVER $ ssh -fNT -R 33060:localhost:3306 xxxxxxx@xxxxxxxxx.cl

LOCAL $ mysql -h 127.0.0.1 -P 33060 -u root -p

And works perfecty :D

  • 写回答

1条回答 默认 最新

  • doubo1871 2017-02-02 14:47
    关注

    here is my php script that connects. Make sure to add your ssh public key to authorized keys on remote server first.

    shell_exec("ssh -f -L 3307:localhost:3306 myuser@myhost sleep 10 >> logfile");
    $DB = new PDO("mysql:host=$servername_local;dbname=$dbname_local;port=3307", $username_local, $password_local);
    $DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块