spatie/ssh
Execute commands over SSH with a simple PHP API. Create a connection with user/host (and optional port), run single or multiple commands synchronously or async, and get a Symfony Process back to inspect success and capture output.
Start by installing the package with Composer: composer require spatie/ssh. Then use the fluent, human-readable Ssh facade to execute remote commands:
use Spatie\Ssh\Ssh;
$process = Ssh::create('deploy', 'myapp.example.com')->execute('php artisan migrate');
if ($process->isSuccessful()) {
echo $process->getOutput();
}
The package wraps Symfony’s Process component — so it’s familiar if you’ve used Laravel’s Process::run() or Artisan::call(). First real-world use case: automate deployment tasks across servers.
execute() — ideal for CI/CD pipelines or health checks.onOutput(fn($type, $line) => ...), not only getOutput() — perfect for streaming logs or interactive CLI wrappers.usePrivateKey()), but when passwords are unavoidable (legacy systems), ensure sshpass is installed — the package fails silently otherwise.upload() and download() for secure file syncs without extra dependencies — backed by scp under the hood.executeAsync() and check their status later, e.g., artisan queue:work --timeout=0 triggered from a web hook.removeBash() when connecting to Windows machines (e.g., via OpenSSH server) to avoid bash wrapper injection in commands.setTimeout() affects the total SSH process runtime, not the remote command — and was historically buggy for scp uploads/downlaods; verify in your version.enableQuietMode() suppresses prompts (e.g., for host key confirmation) — useful for automation, but pair with disableStrictHostKeyChecking() if ephemeral/test hosts are involved.useMultiplexing() for repeated SSH calls to the same host — dramatically reduces connection latency (especially over high-latency networks).php -r "var_dump(\Scape\ssh\Process::create(...)->run(...));" manually — also check getErrorOutput() separately; SSH errors often land there.configureProcess() to tweak Symfony Process options — e.g., disable setTimeout(null) for interactive shells or set custom env vars.How can I help you explore Laravel packages today?