Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel SSH to server not stored in config file

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',
));
like image 678
CRIMUVI Avatar asked Mar 17 '14 20:03

CRIMUVI


1 Answers

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',
));
like image 69
Antonio Carlos Ribeiro Avatar answered Sep 22 '22 04:09

Antonio Carlos Ribeiro