Skip to content

Instantly share code, notes, and snippets.

Forked from sakanaproductions/deploy.php
Created September 13, 2018 17:37
What would you like to do?
PHP Deployer Config File for VPS on Dreamhost
namespace Deployer;
require 'recipe/laravel.php';
// Project name
set('application', '');
// Project repository
set('repository', '');
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);
// Set default stage to staging
set('default_stage', 'staging');
// Shared files/dirs between deploys
add('shared_dirs', []);
// Copy directorys between releases
add('copy_dirs', [
// Writable dirs by web server
add('writable_dirs', []);
// Hosts
->set('deploy_path', '')
->set('deploy_path', '')
// Tasks
task('npm', function () {
if (has('previous_release')) {
$result = run('cp -R {{previous_release}}/node_modules {{release_path}}/node_modules');
writeln('node modules copied');
$result = run('cd {{release_path}} && npm install');
task('build', function () {
$result = run('cd {{release_path}} && pwd');
writeln("Current dir: $result");
// Need to add key to agent every time for SSH to work
desc('Add SSH Key to the SSH Agent');
task('ssh-add', function() {
$result = run('eval `ssh-agent -s`');
writeln("Agent: $result");
$result = run('ssh-add ~/.ssh/bitbucket.key');
writeln("SSH Added");
desc('Copy environment variables');
task('env-vars', 'cp .env{.staging,}');
desc('Install Migration');
task('artisan:migrate-install', '{{bin/php}} {{release_path}}/artisan migrate:install')->once();
task('webpack', function() {
$deploy = get('deploy_path');
if(preg_match('/staging/', $deploy)) {
$result = run('cd {{release_path}} && npm run dev');
} else {
$result = run('cd {{release_path}} && npm run prod');
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// Migrate database before symlink new release.
before('deploy:symlink', 'artisan:migrate');
// in Dreamhost need to add key to ssh-agent
before('deploy:update_code', 'ssh-add');
// copy the right env var to the system
before('artisan:migrate', 'npm');
after('artisan:migrate', 'webpack');
// overwrite shared files for recipe/laravel
set('shared_files', []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment