Execute commands over SSH from PHP with spatie/ssh

A new PHP package released by the fine folks at Spatie is spatie/ssh. Leveraging Symfony\Component\Process\Process it allows you to execute commands over SSH from within your PHP code.

spatie/ssh is probably the easiest way to perform a quick SSH command. It doesn’t have a lot of features, but that’s ok. It’s intended as something very lightweight.

$process = Ssh::create('user', 'example.com')
  ->usePort(2222)
  ->usePrivateKey('/home/user/.ssh/id_rsa')
  ->execute('your favorite command');

Also comes with download and upload functions, using scp under the hood.

Installation per composer:

composer require spatie/ssh

spatie/ssh (GitHub) →
spatie/ssh Introductory Post →

About the Author

Bramus is a Freelance Web Developer from Belgium. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.