Deploy from local development

We can trigger remote deployment over SSH

With the addition of one small package and an additional artisan command we can create a php artisan build command which can be run from the local development environment and cause a deployment on the production server over SSH

Spatie' Remote SSH Runner

Install the package as a development dependency (we will never need this in production).

composer require spatie/ssh --dev

Build Console Command


namespace App\Console\Commands;

use Spatie\Ssh\Ssh;
use Illuminate\Console\Command;

class Build extends Command
    protected $signature = 'build';

    protected $description = 'Run the build command on the remote server';

    protected $server = '';
    protected $account = 'u1119-ahcvzbcli5de';
    protected $port = 18765;
    protected $path = '~/www/';

    public function handle()
        $this->comment('starting build on remote server');

        $process = Ssh::create($this->account, $this->server, $this->port)
        ->onOutput(function($type, $line){
            'cd ' . $this->path,


        if($process->isSuccessful()) {
            $this->comment('Successfully Finished Deployment');
            return Command::SUCCESS;
        } else {
            $this->error('Deployment failed');
            return Command::FAILURE;

Add this file into your project then configure lines 14 to 16 for the hosts SSH connection and then add the folder for your remote website on line 17.

Now, after making changes to your project and pushing to your repository, you can locally run

php artisan build

and your site will be deployed with feedback from the remote server on your console.

Last updated