I'm going to try to explain my problem as clear as possible, feel free to ask me more precision if you didn't understand what I meant and forgive my English this is not my mother tongue.
What I want to do looks simple. Let's say I have 2 servers: S1 and S2.
S1 is the server on which one I have my Laravel 5.5 installed and running.
S2 is a server where I have multiples PHP scripts.
I want to run a PHP script (which is on S2) from a simple click on a button in my Laravel App.
The command I want to run is php theNameOfMyFiles
ssh -tt -p 2222 myRemoteUser@myRemoteIp
. This is working properly.To reach that goal, I tried a bunch of things. First of all, I am using Laravelcollective SSH 5.2 to be able to use SSH from my Laravel app.
My configuration file config/remote.php
, this is where I specify my remote server connections :
return [
default' => 'S1',
'connections' => [
'S1' => [
'host' => '127.0.0.1',
'username' => 'myUsername',
'password' => 'myPassword',
'key' => '',
'keytext' => '',
'keyphrase' => '',
'agent' => '',
'timeout' => 10,
],
'S2' => [
'host' => 'myRemoteIP',
'username' => 'myRemoteUser',
'port' => '2222',
'password' => '',
'key' => '',
'keytext' => '',
'keyphrase' => '',
'agent' => '',
'timeout' => 30,
'directory' => '/home/myRemoteUser/'
]
SSH::into('S2')->run(['mkdir imAtestDirectory']);
Each time I tried to use SSH::into('S2')
I'm getting an Unable to connect to remote server
RuntimeException.
I tried without any SSH key, with my private/public SSH key in the keytext field but I'm still getting the same error.
I tried to put the path to my keys in the key field, but it says the file ~/.ssh/mykey
doesn't exist.
Moving my keys to another place isn't working either, I'm getting the Unable to connect to remote server
again.
SSH::into('S1')->run(['ssh -tt -p 2222 myRemoteUser@myRemoteIp', 'mkdir testDir'])
I tried to reproduce exactly what I was doing in command line because I know that can work. I feel like I'm connecting to S2, when I'm looking at what the SSH command is returning I'm getting [...] The programs included with the Debian GNU/Linux system are free software [...]
which is the same message I'm getting when I'm doing the command in command line , but it's not creating the folder.
I'm running out of ideas, I've been googling for hours but I can't find how to resolve my problem or any other way of doing what I want to do what I want.
If you need any more precision, feel free to ask.
If your actually can log in via "Try 2" you should run the code differently. Append your command with your ssh command. What you are doing now is first running ssh (which probably hangs) and then running "mkdir" when ssh finishes. Instead:
SSH::into('S1')->run(['ssh -tt -p 2222 myRemoteUser@myRemoteIp "cd && mkdir testDir"'])
(I also added cd
to make sure you are in your home directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With