Laravel Deployer Multiple Hosts

Most of us will wind up wanting a Laravel Deployer Multiple Hosts setup. You start out development on one test or staging server, but you often need another production server or more in the end. A setup with a development or staging server, a production web server and a database server for that production web server is ver common. So how do you set this up with’s deployer script?


Laravel app should be installed on a provisioned server and you should have deployer set up on your own box. You can see documentation for both on their respective sites. For Laravel basic provisioning see Stedding.

Single Server

Here an example of a deploy.php script using a Laravel recipe to push to a single Laravel beta or development server

namespace Deployer;

require 'recipe/laravel.php';
require 'vendor/deployer/recipes/cachetool.php';

// Configuration
set('repository', '');
set('default_stage', 'production');
set('git_tty', true); // [Optional] Allocate tty for git on first deployment
set('ssh_type', 'native');
set('cachetool', '/var/run/php/php7.1-fpm.sock');
set('keep_releases', 10);

// Make sure uploads &amp; published aren't overwritten by deploying
set('shared_dirs', [
set('writable_dirs', [

task('db:migrate', function () {
    run("cd {{release_path}} && php artisan migrate");

// Hosts
    ->set('deploy_path', '/var/www/');

// Run database migrations
after('deploy:symlink', 'db:migrate');

// Clear OPCache
after('db:migrate', 'cachetool:clear:opcache');

As you can see we have one single host where we added the user, turned on forward agent for ssh and set the stage and path. But now we want to add another host, user, stage production and a different path setup by Laravel Forge for example. How do we do this?


Well you can put all hosting details in a yaml file and refer to it in your deploy.php script. This you do using


instead of the host block in your deploy.php.The hosts.yml file you would have will look like this:
stage: staging
 roles: app  
 deploy_path: /var/www/

Roles are additional tasks you can add like test and build. For Laravel we have had no need really.

Additional Host in Deploy.php

You can also add an additional host and alias in your script using:

// Hosts 
->set('deploy_path', '/var/www/');
->set('deploy_path', '/home/forge/');

Here you see two hosts with aliases: beta, production. These you can then use in your command:

dep deploy production 
dep deploy beta


Tagged in : Tagged in : , ,
Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.