简体   繁体   English

使用SSH与Laravel进行mysql_connect

[英]Use SSH to mysql_connect with Laravel

I need to connect to a certain server and insert stuff into the database from another webapp 我需要连接到某个服务器,然后将内容从另一个Web应用程序插入数据库中

In order to do so, I need to have full SSH access. 为此,我需要具有完全的SSH访问权限。

The steps follows 1. $articles = Article::all(); 步骤如下:1. $ articles = Article :: all(); 2. Create an SSH tunnel 3. mysql_connect(remote) -> mysql_select_db -> mysql_query(insert $articles) -> mysql_close 2.创建一个SSH隧道3. mysql_connect(远程)-> mysql_select_db-> mysql_query(插入$ articles)-> mysql_close

It's possible with php's built in ssh2:s functions. php内置的ssh2:s函数是可能的。

-- -

Now, my question is. 现在,我的问题是。 What is the best way to do this using smart features in Laravel? 使用Laravel中的智能功能执行此操作的最佳方法是什么?

Could etc Laravels SSH::run functionality be of any productive use here? Laravels的SSH :: run功能可以在这里发挥任何生产用吗? Maybe a reccommended way would be to create models for the foreign database? 推荐的方法是为外部数据库创建模型?

Edit: I need this to be done differently for all environments also. 编辑:我还需要针对所有环境以不同的方式进行此操作。 I have different private SSH keys on the server and localhost etc. 我在服务器和本地主机等上有不同的私钥SSH密钥。

Based on your server, you can use Laravel remote component 根据您的服务器,您可以使用Laravel 远程组件

Fortrabbit has awesome SSH workflow. Fortrabbit具有很棒的SSH工作流程。 They allow you to work remotely with your app and with you database. 它们使您可以远程处理应用程序和数据库。

UPDATE: 更新:

Remote component is a provider for Laravel SSH capabilities. 远程组件是Laravel SSH功能的提供者。 It allows you to work remotely with your application. 它使您可以远程处理应用程序。 All setting must be done in app/config/remote.php file. 所有设置必须在app / config / remote.php文件中完成。 There you have to enter you server credentials. 在这里您必须输入服务器凭据。 Take a look at Remote package in Laravel. 看一下Laravel中的Remote软件包。

最好的方法是将mysql配置为允许您的计算机连接到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM