The PHP SSH Connection package provides an elegant syntax to connect to SSH servers and execute commands. It supports both password and public-private keypair authentication, and can easily capture command output and errors.
You can install the PHP SSH Connection package by running the following Composer command.
composer require divineomega/php-ssh-connection
$connection = (new SSHConnection())
->to('test.rebex.net')
->onPort(22)
->as('demo')
->withPassword('password')
// ->withPrivateKey($privateKeyPath)
->connect();
$command = $connection->run('echo "Hello world!"');
$command->getOutput(); // 'Hello World'
$command->getError(); // ''
$connection->upload($localPath, $remotePath);
$connection->download($remotePath, $localPath);