Pages

30 April, 2022

Run Artisan Commands on Remote Servers

 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:

1php artisan remote cache:clear
2 
3# Raw ls command on the server
4php artisan remote ls --raw
5 
6# Raw ls with flags
7php artisan remote --raw "ls -a"
8 
9 
10# Defining which host configuration to use
11php 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:

1return [
2 'hosts' => [
3 'default' => [
4 'host' => env('REMOTE_HOST'),
5 'port' => env('REMOTE_PORT', 22),
6 'user' => env('REMOTE_USER'),
7 'path' => env('REMOTE_PATH'),
8 ],
9 'example2' => [
10 'host' => env('EXAMPLE2_REMOTE_HOST'),
11 'port' => env('EXAMPLE2_REMOTE_PORT', 22),
12 'user' => env('EXAMPLE2_REMOTE_USER'),
13 'path' => env('EXAMPLE2_REMOTE_PATH'),
14 ],
15 ],
16];

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:

29 April, 2022

Migrate One Database to Another in a Laravel Project

 Migrate DB is a package by Andrey Helldar to migrate one database to another in Laravel apps. Configuring two databases in the config/database.php file, you can use the connection name to run the migration:

1php artisan db:migrate \
2 --schema-from=example \
3 --schema-to=example2

The command will perform all migrations on the source and destination databases and transfer records from the first database to the second.

Currently, this package supports the following databases:

  • MySQL
  • PostgreSQL
  • MSSQL

You can learn more about this package, get full installation instructions, and view the source code on GitHub.


28 April, 2022

Manage Scheduled Tasks Through a Dashboard

 Laravel Database Schedule is a package to schedule tasks through a UI dashboard without having to redeploy your application. While you'll still need to write the scheduled task commands, once created, you can use the provided /schedule endpoint to configure a task's schedule:

Database schedule table list

Here are the highlight features this package provides for your apps:

  • Manage scheduled tasks via a GUI dashboard (create, edit, delete, disable)
  • Custom authentication logic for dashboard access using Laravel gates
  • Configurable parameters via UI
  • Configure Before and after webhook endpoints
  • Send task output via email
  • See command run history from the dashboard
  • Configure job rules for no overlap, executing on one server, run even during maintenance mode, etc.

You can learn more about this package, get full installation instructions, and view the source code on GitHub.