SSH connection via PHP - Laravel












4















Hello everyone



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.





My goal



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





The things you have to know




  1. In command line, I can connect in SSH to S2 via S1: ssh -tt -p 2222 myRemoteUser@myRemoteIp. This is working properly.

  2. Most of my test will show some tries of folder creation because it is easier to see if a folder has been created instead of checking if a script is running.




My different tries



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/'
]


Try 1



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.



Try 2



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.





Help me, please



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.





Edits




  1. I've been trying few other syntax but without success. I'm still open to any suggestions, I'll try next what Dammeul said (check if port 2222 is open on both ends)










share|improve this question

























  • Is port 2222 open on both ends?

    – Dammeul
    Aug 29 '18 at 13:52













  • I can use telnet myRemoteHost 2222 from S1. I can't use telnet myHost 2222 from S2.

    – McKenneii
    Aug 29 '18 at 13:59











  • Sounds like the port is closed on S2 potentially. Worth checking if you can open it / see if it is open

    – Dammeul
    Aug 29 '18 at 14:01













  • Wouldn't be a problem as well for when I'm using ssh -tt -p 2222 myRemoteUser@myRemoteIp in command line as well then? (Because this is working perfectly ...)

    – McKenneii
    Aug 29 '18 at 14:05











  • You wouldn't use your public key for authentication. What user is the web server running as? Does it have access to your key?

    – Devon
    Aug 29 '18 at 15:24
















4















Hello everyone



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.





My goal



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





The things you have to know




  1. In command line, I can connect in SSH to S2 via S1: ssh -tt -p 2222 myRemoteUser@myRemoteIp. This is working properly.

  2. Most of my test will show some tries of folder creation because it is easier to see if a folder has been created instead of checking if a script is running.




My different tries



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/'
]


Try 1



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.



Try 2



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.





Help me, please



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.





Edits




  1. I've been trying few other syntax but without success. I'm still open to any suggestions, I'll try next what Dammeul said (check if port 2222 is open on both ends)










share|improve this question

























  • Is port 2222 open on both ends?

    – Dammeul
    Aug 29 '18 at 13:52













  • I can use telnet myRemoteHost 2222 from S1. I can't use telnet myHost 2222 from S2.

    – McKenneii
    Aug 29 '18 at 13:59











  • Sounds like the port is closed on S2 potentially. Worth checking if you can open it / see if it is open

    – Dammeul
    Aug 29 '18 at 14:01













  • Wouldn't be a problem as well for when I'm using ssh -tt -p 2222 myRemoteUser@myRemoteIp in command line as well then? (Because this is working perfectly ...)

    – McKenneii
    Aug 29 '18 at 14:05











  • You wouldn't use your public key for authentication. What user is the web server running as? Does it have access to your key?

    – Devon
    Aug 29 '18 at 15:24














4












4








4


0






Hello everyone



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.





My goal



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





The things you have to know




  1. In command line, I can connect in SSH to S2 via S1: ssh -tt -p 2222 myRemoteUser@myRemoteIp. This is working properly.

  2. Most of my test will show some tries of folder creation because it is easier to see if a folder has been created instead of checking if a script is running.




My different tries



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/'
]


Try 1



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.



Try 2



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.





Help me, please



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.





Edits




  1. I've been trying few other syntax but without success. I'm still open to any suggestions, I'll try next what Dammeul said (check if port 2222 is open on both ends)










share|improve this question
















Hello everyone



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.





My goal



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





The things you have to know




  1. In command line, I can connect in SSH to S2 via S1: ssh -tt -p 2222 myRemoteUser@myRemoteIp. This is working properly.

  2. Most of my test will show some tries of folder creation because it is easier to see if a folder has been created instead of checking if a script is running.




My different tries



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/'
]


Try 1



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.



Try 2



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.





Help me, please



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.





Edits




  1. I've been trying few other syntax but without success. I'm still open to any suggestions, I'll try next what Dammeul said (check if port 2222 is open on both ends)







php bash laravel laravel-5 ssh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 4 '18 at 12:07







McKenneii

















asked Aug 29 '18 at 13:50









McKenneiiMcKenneii

879




879













  • Is port 2222 open on both ends?

    – Dammeul
    Aug 29 '18 at 13:52













  • I can use telnet myRemoteHost 2222 from S1. I can't use telnet myHost 2222 from S2.

    – McKenneii
    Aug 29 '18 at 13:59











  • Sounds like the port is closed on S2 potentially. Worth checking if you can open it / see if it is open

    – Dammeul
    Aug 29 '18 at 14:01













  • Wouldn't be a problem as well for when I'm using ssh -tt -p 2222 myRemoteUser@myRemoteIp in command line as well then? (Because this is working perfectly ...)

    – McKenneii
    Aug 29 '18 at 14:05











  • You wouldn't use your public key for authentication. What user is the web server running as? Does it have access to your key?

    – Devon
    Aug 29 '18 at 15:24



















  • Is port 2222 open on both ends?

    – Dammeul
    Aug 29 '18 at 13:52













  • I can use telnet myRemoteHost 2222 from S1. I can't use telnet myHost 2222 from S2.

    – McKenneii
    Aug 29 '18 at 13:59











  • Sounds like the port is closed on S2 potentially. Worth checking if you can open it / see if it is open

    – Dammeul
    Aug 29 '18 at 14:01













  • Wouldn't be a problem as well for when I'm using ssh -tt -p 2222 myRemoteUser@myRemoteIp in command line as well then? (Because this is working perfectly ...)

    – McKenneii
    Aug 29 '18 at 14:05











  • You wouldn't use your public key for authentication. What user is the web server running as? Does it have access to your key?

    – Devon
    Aug 29 '18 at 15:24

















Is port 2222 open on both ends?

– Dammeul
Aug 29 '18 at 13:52







Is port 2222 open on both ends?

– Dammeul
Aug 29 '18 at 13:52















I can use telnet myRemoteHost 2222 from S1. I can't use telnet myHost 2222 from S2.

– McKenneii
Aug 29 '18 at 13:59





I can use telnet myRemoteHost 2222 from S1. I can't use telnet myHost 2222 from S2.

– McKenneii
Aug 29 '18 at 13:59













Sounds like the port is closed on S2 potentially. Worth checking if you can open it / see if it is open

– Dammeul
Aug 29 '18 at 14:01







Sounds like the port is closed on S2 potentially. Worth checking if you can open it / see if it is open

– Dammeul
Aug 29 '18 at 14:01















Wouldn't be a problem as well for when I'm using ssh -tt -p 2222 myRemoteUser@myRemoteIp in command line as well then? (Because this is working perfectly ...)

– McKenneii
Aug 29 '18 at 14:05





Wouldn't be a problem as well for when I'm using ssh -tt -p 2222 myRemoteUser@myRemoteIp in command line as well then? (Because this is working perfectly ...)

– McKenneii
Aug 29 '18 at 14:05













You wouldn't use your public key for authentication. What user is the web server running as? Does it have access to your key?

– Devon
Aug 29 '18 at 15:24





You wouldn't use your public key for authentication. What user is the web server running as? Does it have access to your key?

– Devon
Aug 29 '18 at 15:24












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer


























  • Thanks a lot ! Your solution works perfectly ! I feel dumb about not trying that kind of syntax though

    – McKenneii
    Jan 21 at 9:48












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52079055%2fssh-connection-via-php-laravel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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.






share|improve this answer


























  • Thanks a lot ! Your solution works perfectly ! I feel dumb about not trying that kind of syntax though

    – McKenneii
    Jan 21 at 9:48
















1














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.






share|improve this answer


























  • Thanks a lot ! Your solution works perfectly ! I feel dumb about not trying that kind of syntax though

    – McKenneii
    Jan 21 at 9:48














1












1








1







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 12 '18 at 9:05

























answered Nov 16 '18 at 9:21









Esben DamgaardEsben Damgaard

665




665













  • Thanks a lot ! Your solution works perfectly ! I feel dumb about not trying that kind of syntax though

    – McKenneii
    Jan 21 at 9:48



















  • Thanks a lot ! Your solution works perfectly ! I feel dumb about not trying that kind of syntax though

    – McKenneii
    Jan 21 at 9:48

















Thanks a lot ! Your solution works perfectly ! I feel dumb about not trying that kind of syntax though

– McKenneii
Jan 21 at 9:48





Thanks a lot ! Your solution works perfectly ! I feel dumb about not trying that kind of syntax though

– McKenneii
Jan 21 at 9:48




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52079055%2fssh-connection-via-php-laravel%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues