Deploy laravel on the server with Envoy

Tram Ho


Hello everyone, maybe everyone does not know, laravel has a tool to deploy directly to the server 1 extremely fast and convenient that is Envoy.

Envoy has a very clean, well-written way to identify common tasks you’ll run on servers. Using Blade-style syntax, you can easily set up tasks to deploy using Artisan commands with great ease.

Note: Laravel Envoy currently only supports Mac and Linux operating systems.


First, you need to install Envoy with the Composer command:

Here I use global to install, ie it will only need to install 1 time, the next time do not need to install anymore.

Install envoy

Declaring the task

All your Envoy tasks must be specified in the Envoy.blade.php file in the project’s root directory:

Above I have used 1 @servers membrane has been defined at the top of the file, this allows you to refer to these servers in the task notification option.

In @task declarations, you can write the commands needed to execute on the server.

If you want to execute commands under localhost, then you specify the server’s IP address is

Use setup

Sometimes, you may want to execute some PHP code before performing Envoy tasks. You can use the @setup command to declare variables and run PHP before any other envoy tasks are executed:

If you need to require other PHP files before the envoy task is executed, you can use the @include command like the example below:

Use variable

If needed, you can pass custom values ​​into Envoy tasks with the command:

You can access options in your task through the “echo” syntax of Blade. You can also use if statement and loop in your task.

For example:

The code above I checked the branch variable passed first, if there is a branch, it will execute pull code from the branch. Easy right?

Use story

When you have multiple tasks that you want to combine to run once, use the story , which will group a group of tasks under a single name, this allows you to group small tasks, focusing on large tasks.

For example, a deployment list can run git and composer tasks by listing task names in its story :

How to run the story as usual:

Multiple Servers

Envoy will allow you to easily run a task on multiple servers.

Parallel Execution

By default, tasks are executed on each server. This means that a task will have to be completed running on the first server before proceeding on the second server. If you want to run a task on multiple servers in parallel, you need to add the parallel option to your task declaration:

Confirming Task Execution

A very important function while deploying is to confirm , confirm the action first and then execute.

This option is useful for me to confirm that you really want to perform this task:



The perspective is set when your project has many parties such as app, api, backend, frontend. There will be times when you need to notify a certain service about the deployment results for the parties to know.

Envoy assisted in sending notifications to Slack after each task was executed. The @slack command will accept the Slack hook URL and channel name.

You can retrieve your webhook URL by creating the “WebHooks” integration in your Slack dashboard. You must pass the entire webhook URL into the @slack directive:


Thanks for reading !.

Share the news now

Source : Viblo