Run Artisan Commands on Remote Servers

Published on by

Run Artisan Commands on Remote Servers image

Laravel Remote is a package by Spatie that provides a command to execute Artisan commands on a remote server.

Here are some examples of remote commands from the documentation:

php artisan remote cache:clear
# Raw ls command on the server
php artisan remote ls --raw
# Raw ls with flags
php artisan remote --raw "ls -a"
# Defining which host configuration to use
php artisan remote cache:clear --host=my-other-host

At the heart of the package's configuration, you define hosts for remote servers that you want to interact with. In order to execute a command on a given host, you can use the --host flag for the desired configuration:

return [
'hosts' => [
'default' => [
'host' => env('REMOTE_HOST'),
'port' => env('REMOTE_PORT', 22),
'user' => env('REMOTE_USER'),
'path' => env('REMOTE_PATH'),
'example2' => [
'host' => env('EXAMPLE2_REMOTE_HOST'),
'port' => env('EXAMPLE2_REMOTE_PORT', 22),
'user' => env('EXAMPLE2_REMOTE_USER'),
'path' => env('EXAMPLE2_REMOTE_PATH'),

Under the hood, this package uses Spatie's ssh package, a lightweight PHP library to execute commands over SSH.

If you'd like to follow the author Freek Van der Herten to see how to build this package, he live-streamed it on YouTube. Learn practical examples from one of the most prolific Laravel package developers, where he shows you tips on how to build Laravel packages from scratch:

Learn More

To get started with spatie/laravel-remote, read the documentation available in the project's GitHub readme. Freek also wrote a blog post that goes into more detail about the package.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.


Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Version 4 of Tinkerwell is available now. Get the most popular PHP scratchpad with all its new features and simplify your development workflow today.

Visit Tinkerwell
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo


The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo


Providing innovation and stability to ensure your web application succeeds.

Shift logo


Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

LoadForge logo


Easy, affordable load testing and stress tests for websites, APIs and databases.

Paragraph logo


Manage your Laravel app as if it was a CMS – edit any text on any page or in any email without touching Blade or language files.

Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
Bacancy - Staff Augmentation logo

Bacancy - Staff Augmentation

Leave your web app development hustles to the leading IT Staff Augmentation Service Providers. Choose from an extensive pool of 1050+ developers and give yourself the sigh of success you deserve with Bacancy. Get In Touch Today!

Bacancy - Staff Augmentation logo

Save hours of manually writing Code Documentation, Comments & DocBlocks, Test suites and Refactoring.
Rector logo


Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies


The latest

View all →
October CMS v3.6 Ships Today, Full of New Features image

October CMS v3.6 Ships Today, Full of New Features

Read article
Laracon EU Videos are now out image

Laracon EU Videos are now out

Read article
Use Google's Gemini AI in Laravel image

Use Google's Gemini AI in Laravel

Read article
PhpStorm is getting a brand new terminal image

PhpStorm is getting a brand new terminal

Read article
Six Essential Plugins for Visual Studio Code image

Six Essential Plugins for Visual Studio Code

Read article
Modularize Your Laravel Application With the Modular Package image

Modularize Your Laravel Application With the Modular Package

Read article