Use Deployer to deploy Laravel Application

Tram Ho

Today we will learn a tool to support auto deploying PHP applications and especially with Laravel, Deployer.

1. Install Deployer

  • To install Deployer is quite simple, on the Deployer home page also instructed, you just need to run the following commands:

Once installed, move to the directory where the project is located (under local) and run

then it will generate deploy.php file in your project

2. Use Deployer

  • Next, we config with deploy.php file

1. Configuration

  • To use configuration variables, we use the set() function, to get it out we use the get() function.

2. Task

  • To define the task to execute, you use the task() function, but you can also describe the task with the desc() function, for example:

  • To perform a task:

  • To display the available commands:

  • You can also combine several tasks into one task:

  • You can define tasks that can run before or after other tasks:

3. Host

  • You can define host by the host() function, for example:


  • : is the domain or IP you will deploy
  • stage : Name of the environment you will deploy (staging, production) – Any name will be provided as long as you type the command to type the stage name correctly 😄

4. Flow

  • The general deployment flow will look like this:


  • deploy:prepare : Prepare deploy, check deploy_path , if not, create it. It also checks for the existence of paths:
    • relesases : In this directory, releases releases will be stored
    • shared : File sharing on all releases
    • .dep : metadata used by Deployer
  • deploy:lock : Deploy key to run only 1 deploy process at the same time, check the existence of .dep/deploy.lock file, if deply process is canceled by Ctrl + C , run deploy:unlock to delete this file. go. In case of unsuccessful deploy, then deploy:unlock will automatically activate
  • deploy:release : Create a folder release based on the configuration release_name while reading files .dep/releases to get a list of the releases made before do.Ngoai, if in deploy_path have symlinks the previous release, it will be deleted
  • deploy:update_code : pull code from github
  • deploy:shared : create deploy:shared files and shared folders for the files that we define to share across versions. You can specify shared folders and files at shared_dirs and shared_files , the process is divided into steps: + Copy the folder from release_path to shared if it doesn’t exist. + Delete the release_path directory + symlink the folder from shared to release_path .
  • deploy:writable : Set write permissions for the files listed in writable_dirs .
  • deploy:vendors : Run composer install for the application.
  • deploy:clear_paths : Delete the specified directory in clear_paths
  • deploy:symlink : symlink the current version to release_path .
  • cleanup : Clean old releases
  • success : Print the success message.
  • And here is the configuration file I have configured in the deploy.php file:

And to run, we run:

^^ or you can also run

to see details of the deploying process, what does it run?


  • To run this guy deploy, you need to have ssh key connect to the server
  • When you run the first time, you do not run the migrate task, the next deploy run can run the migrate task, and each time the code is merged, you just need to run

  • If you want to rollback to an earlier release, just run

  • Above is what I tried with Deployer and success 😄



Use deployer to deploy laravel application

Share the news now

Source : Viblo