Deploy a Laravel project using deployer (Part 1)

Tram Ho

Hello everyone, so we meet again after our endless laziness. As you know, deploying is the final stage to bring products – our brainchild to the user. And lately, I have been practicing deploying things, so I should share with you about Deployer spontaneously. A tool that supports auto deploying for PHP applications especially supports laravel.
And to make it easier for everyone to become familiar with and monitor the progress, I will divide the structure into 2 parts:

  • Learn how to set up and some basic settings.
  • Process of creating tasks and deploying a sample project laravel on host.

Now let’s find out the first part

Install deployer

This step is the most ii step in history. Everything is available on the homepage so I will keep it short. Basically it will have 3 such steps:

So now you can use Deployer through the dep command in the terminal.

Use deployer

To use the deployer, you need to have the following combo:

  • A php project can be run (sadly, create a directory and echo "Hello world!"; Okay. Here, I already have a laravel code project so please excuse me from the muddy step.
  • A deploy.php file to run auto deploy. This file will contain some settings that we will explore in the following sections.

Configuration parameters

To set the configuration parameters you use the method set according to the syntax

and use the get method to get the values ​​set.

Each parameter can be overridden for different hosts:

You can also use a callback to set values ​​for the parameters. This callback will be made on the host from the first time I use get .

You can use parameters in the run method by using the braces {{ param_name }} instead of using the get method.

To see the list of running parameters, use the following command at the terminal

Here is a list of common parameters and their meanings:


This is where the application is deployed on the host. You should define this parameter for all hosts you have. For example, if you want to deploy to your home directory.


The current host name, automatically set by the host method


The current username, the default will be the name of the current git user

Or you can also overwrite in deploy.php file using the env variable:


The full address to the current release directory.
By default, release_path is used for simple tasks.


The previous release point if it exists. On the other hand, this variable does not exist. Can be used for resources that do not need to be installed multiple times.


Number of releases retained. -1 for unlimited, the default is set to 5 .


Git repository of the application.
To use a private repo, you need to put the host’s ssh key into the repo as a Deploy key.


Branch will be selected for deployment.
If you want to deploy a specific tag or revision, you need to use the --tag and --revision in the dep deploy command.

Note that the tag has a higher priority than the branch and is lower than the revision .


List of shared folders.


List of shared files.


List of folders copied between releases.


The action with composer. The default is to install to install the necessary packages for the project.


Composer options.


An array containing environment variables.


Above is how to install and use the deployer for auto deploying your PHP application (specifically the Laravel application) to the host. In the next section, I will share more about the task, the basic flow of a deploy process using deployer and sample deploy.php file for Laravel application for your reference.
All the above information is translated from the homepage so if you have any problem, you can refer to the docs
Thank you for trying to read through this post, any suggestions please leave below the comment section.

Share the news now

Source : Viblo