Deployer Documentation

repository·master·Indexed 27 days ago

https://github.com/deployphp/deployer

A PHP-based deployment automation tool for zero-downtime deployments and server provisioning. It features a CLI (`dep`), built-in recipes for PHP frameworks, and a comprehensive API for managing remote hosts, tasks, and file transfers via rsync. Requires PHP 8.2 or higher.

Tokens
51.8K
Snippets
200
Records
492
Agent score
95%

What's inside Deployer

  1. Overview of Deployer

    master
    Deployer is a PHP deployment tool designed to automate deployment processes. It provides features such as automatic server provisioning, zero-downtime deployments, and built-in recipes for most popular PHP frameworks.
  2. Configure Shopware Host Settings

    master

    When setting up your host for Shopware deployment, you must define the repository and host-specific configurations. Key settings include deploy_path, http_user, http_group, and become (to ensure tasks run with correct permissions for cache files).

    set('repository', 'git@github.com:shopware/production.git');
    
    host('SSH-HOSTNAME')
        ->set('remote_user', 'SSH-USER')
        ->set('deploy_path', '/var/www/shopware')
        ->set('http_user', 'www-data')
        ->set('http_group', 'www-data')
        ->set('writable_mode', 'chmod')
        ->set('writable_recursive', true)
        ->set('become', 'www-data');
  3. Use the Crontab Recipe to manage cron jobs

    master

    The Crontab recipe allows you to manage a specific section of the server's crontab file. It creates a section identified by a unique identifier (defaulting to the application name) so that Deployer can manage only the jobs related to your application without interfering with other system cron jobs.

    To use it, require the recipe in your deployment script, configure your jobs, and hook the crontab:sync task to run after a successful deployment.

    require 'contrib/crontab.php';
    
    // Sync jobs after a successful deployment
    after('deploy:success', 'crontab:sync');
    
    // Define your cron jobs
    add('crontab:jobs', [
        '* * * * * cd {{current_path}} && {{bin/php}} artisan schedule:run >> /dev/null 2>&1',
    ]);
  4. Use CIMonitor tasks in your deployment flow

    master

    To monitor the lifecycle of a deployment, hook the CIMonitor tasks into your deployment process using before and after hooks.

    • To notify when a deployment starts: before('deploy', 'cimonitor:notify');
    • To notify on success: after('deploy:success', 'cimonitor:notify:success');
    • To notify on failure: after('deploy:failed', 'cimonitor:notify:failure');
    before('deploy', 'cimonitor:notify');
    after('deploy:success', 'cimonitor:notify:success');
    after('deploy:failed', 'cimonitor:notify:failure');
  5. Use Mattermost notification tasks

    master

    You can trigger Mattermost notifications at different stages of your deployment by attaching specific tasks to deployment hooks.

    • Notify at start of deployment: Use mattermost:notify on the before('deploy', ...) hook.
    • Notify on success: Use mattermost:notify:success on the after('deploy:success', ...) hook.
    • Notify on failure: Use mattermost:notify:failure on the after('deploy:failed', ...) hook.
  6. Deploy a Laravel project using the Laravel recipe

    master

    To use the pre-configured Laravel deployment workflow, include the Laravel recipe in your deployment script using require 'recipe/laravel.php';.

    The deploy task for Laravel includes several automated steps:

    • Preparation: deploy:prepare (includes deploy:info, deploy:setup, deploy:lock, deploy:release, deploy:update_code, deploy:env, deploy:shared, and deploy:writable).
    • Dependencies: deploy:vendors installs composer dependencies.
    • Laravel Specifics: artisan:storage:link (creates symbolic links), artisan:optimize (caches bootstrap files), and artisan:migrate (runs database migrations).
    • Publishing: deploy:publish (includes deploy:symlink, deploy:unlock, and deploy:cleanup).
    • Post-deployment: artisan:reload (reloads running services).
    require 'recipe/laravel.php';
  7. Upgrade from 5.x to 6.x

    master

    Branch Option Priority

    In v6, if a host has a branch(...) parameter, the --branch CLI option will no longer override it. To restore old behavior, use a callback:

    host('prod')->set('branch', function () {
        return input()->getOption('branch') ?: 'production';
    });

    API Changes

    • run and runLocally now return a string instead of a Deployer\Type\Result object.
      • Replace run('...')->toString() with run('...').
      • Replace run('...')->toBool() with test('...').
    • env_vars is renamed to env.
      • set('env_vars', 'FOO=bar') $\rightarrow$ set('env', ['FOO' => 'bar']).
      • If using the Symfony recipe, use set('symfony_env', 'prod') instead of set('env', 'prod').
  8. Use the Writable Recipe

    master

    To enable the writable directory management features in your deployment, include the writable recipe in your deploy.php file.

    This recipe provides configuration options to manage directory permissions (via chown, chgrp, chmod, acl, etc.) and a deploy:writable task to apply these permissions.

    require 'recipe/deploy/writable.php';