Introducing Artisan Remote
Tags: PHP, Laravel, Electron, Desktop App

Over the years, I’ve SSH’ed into dozens of servers to execute Laravel Artisan commands. Creating some bash shortcuts made things a bit easier, luckily. On some occasions, though, clients did not support SSH, and in other cases, they did, but it was a terrible process of back-and-forth emails between clients and hosting providers to get things sorted.

I started to play around with Electron (build cross-platform desktop apps with JavaScript, HTML, and CSS) and had the idea to create something that would fix this issue as my first Electron project. So without further ado, I would like to introduce you to Artisan Remote, the perfect companion for your Laravel applications.

Artisan Remote is a desktop application that allows you to run artisan commands with a simple click and view the output of earlier executed commands across multiple Laravel applications.

Behind the scenes, the application utilizes HTTP endpoints to send and retrieve information from your Laravel applications. To allow Laravel artisan commands to execute commands via HTTP endpoints instead of the command line, I’ve created a simple package that exposes your artisan commands to the web.

Getting started

Open your terminal, switch to your favorite Laravel application, and install the Artisan Remote composer package:

composer require philo/artisan-remote

Next, you will need to publish the associated configuration file with the vendor:publish command:

php artisan vendor:publish --provider="Philo\ArtisanRemote\ArtisanRemoteServiceProvider"

This command will place a configuration file in your Laravel application’s config directory config/artisan-remote.php . Inside the configuration file, you define which commands are available via the HTTP endpoint.

<?php



return [

'commands' => [

\Illuminate\Foundation\Console\UpCommand::class,

\Illuminate\Foundation\Console\DownCommand::class,

\Illuminate\Cache\Console\ClearCommand::class,

],

//

];

Given the nature and possible power of commands, you can’t execute any without authentication. So Artisan Remote requires you to define at least one API authentication token. You can choose to restrict API tokens only to perform specific commands. For example, you might want to expose the up and down command to your client and give yourself access to execute the queue:restart command:

<?php



return [

'commands' => [

\Illuminate\Foundation\Console\UpCommand::class,

\Illuminate\Foundation\Console\DownCommand::class,

\Illuminate\Cache\Console\ClearCommand::class,

],

'auth' => [

'c557510d-7f2d-4e69-b600-d1050e5dc896' => [

\Illuminate\Foundation\Console\UpCommand::class,

\Illuminate\Foundation\Console\DownCommand::class,

\Illuminate\Cache\Console\ClearCommand::class,

],

'240d4017-d7e3-4b30-8d74-6cb60816caf2' => ['*'],

],

//

];

Best practices recommend using environment variables for sensitive information. So be sure to adjust your config file accordingly:

env('MY_ARTISAN_REMOTE_API_KEY') => ['*'],

For those who would like to be able to bring their application back online after running the down command ;) be sure to allow the desktop application to interact with your application when in maintenance mode by listing the API endpoint as an exception.

You can add this exception in the CheckForMaintenanceMode.php middleware in Laravel 7 or PreventRequestsDuringMaintenance.php in Laravel 8.

/**

* The URIs that should be reachable while maintenance mode is enabled.

*

* @var array

*/

protected $except = [

'artisan-remote/*'

];

Download and configure the desktop application

Now it’s time for the exciting part. Click here to download the desktop application for your operating system and launch it!

To get started, click “Add new Laravel application.” and enter your application URL and the API token you’ve set in the artisan-remote.php configuration file.

That’s it! You’ve just added your first Laravel application to the Artisan Remote desktop application. To execute your first command, click on your application’s name; this will present you with an overview of the commands available per your configuration.

Click on the blue play icon on the right side of the command you would like to execute. Clicking the icon will display the available options for the command you’ve chosen. In case your command has no options, click the “Execute Command” button.

Once the command execution finishes, a new window will pop-up with your command’s output. If you want, you can see the history of commands you’ve run earlier by clicking “Execution history” located in the cog menu.

The Artisan Remote composer package and the desktop application are available for free. The desktop application source code is not available for now as I used Tailwind UI’s commercial components. Depending on the amount of interest from people, I might update the design and remove the Tailwind UI components so I can open-source the project.

Feedback is always welcome. If you want to report a bug, submit an idea, go to the repository, and create an issue.

Download for Mac, Windows or Linux.