Laravel Envoy
Introduction
Laravel Envoy is a tool for executing common tasks you run on your remote servers. Using Blade style syntax, you can easily setup tasks for deployment, Artisan commands, and more. Currently, Envoy only supports the Mac and Linux operating systems. However, Windows support is achievable using WSL2.
Installation
First, install Envoy into your project using the Composer package manager:
composer require laravel/envoy --dev
Once Envoy has been installed, the Envoy binary will be available in your application's vendor/bin
directory:
php vendor/bin/envoy
Writing Tasks
Defining Tasks
Tasks are the basic building block of Envoy. Tasks define the shell commands that should execute on your remote servers when the task is invoked. For example, you might define a task that executes the php artisan queue:restart
command on all of your application's queue worker servers.
All of your Envoy tasks should be defined in an Envoy.blade.php
file at the root of your application. Here's an example to get you started:
@servers(['web' => ['user@192.168.1.1'], 'workers' => ['user@192.168.1.2']])
@task('restart-queues', ['on' => 'workers'])
cd /home/user/example.com
php artisan queue:restart
@endtask
As you can see, an array of @servers
is defined at the top of the file, allowing you to reference these servers via the on
option of your task declarations. The @servers
declaration should always be placed on a single line. Within your @task
declarations, you should place the shell commands that should execute on your servers when the task is invoked.
Local Tasks
You can force a script to run on your local computer by specifying the server's IP address as 127.0.0.1
:
@servers(['localhost' => '127.0.0.1'])
Importing Envoy Tasks
Using the @import
directive, you may import other Envoy files so their stories and tasks are added to yours. After the files have been imported, you may execute the tasks they contain as if they were defined in your own Envoy file:
@import('vendor/package/Envoy.blade.php')