I have a project that involves server management and I need to execute some SSH commands.
In Laravel I have the SSH utility (remote), but I have to put the configuration in a file.
I need to connect with the credentials stored in a model from the database.
Any ideas how can I do this?
Something like this:
$connArray = array(
"server" => "8.8.8.8",
"port" => "22",
"user" => "root",
"pass" => "123456"
);
SSH::into($connArray)->run(array(
'cd /var/www',
'git pull origin master',
));
You set edit configuration at runtime:
Create a new connection
(You can safely omit this part, Laravel will create the configuration entry automatically for you, but you might need to create it just for your developers to remember that some configurations are being set during runtime).
'connections' => array(
'runtime' => array(
'host' => '',
'username' => '',
'password' => '',
'key' => '',
'keyphrase' => '',
'root' => '/var/www',
),
),
Set them and do whatever you need:
Config::set('remote.connections.runtime.server', '8.8.8.8');
Config::set('remote.connections.runtime.port', '22');
Config::set('remote.connections.runtime.user', 'root');
Config::set('remote.connections.runtime.pass', '123456');
SSH::into('runtime')->run(array(
'cd /var/www',
'git pull origin master',
));
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