Deployer Documentation
repository·master·Indexed 27 days ago
https://github.com/deployphp/deployerA 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.
What's inside Deployer
- 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.
Install and initialize Deployer
masterAfter installing Deployer, navigate to your project directory and rundep init. This command will prompt you with several questions to create adeploy.phpordeploy.yamlrecipe. This file defines your hosts, tasks, and imported recipes.dep initInstall the Slack Recipe
masterTo use Slack notifications in your deployment process, require the Slack recipe file in your deployment script:
require 'contrib/slack.php';You will also need a Slack incoming webhook URL to provide to the configuration.
Install the Yammer Recipe
masterTo use Yammer notifications in your deployment process, require the Yammer recipe file in your deployment configuration (usually
deploy.php).require 'contrib/yammer.php';Configure Shopware Host Settings
masterWhen 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, andbecome(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');Set up the Deployer CLI alias
masterFor project-based installs, it is recommended to alias
depto the vendor binary to simplify command execution.alias dep='vendor/bin/dep'Use the Crontab Recipe to manage cron jobs
masterThe 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:synctask 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', ]);Use CIMonitor tasks in your deployment flow
masterTo monitor the lifecycle of a deployment, hook the CIMonitor tasks into your deployment process using
beforeandafterhooks.- 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');- To notify when a deployment starts:
Use Mattermost notification tasks
masterYou can trigger Mattermost notifications at different stages of your deployment by attaching specific tasks to deployment hooks.
- Notify at start of deployment: Use
mattermost:notifyon thebefore('deploy', ...)hook. - Notify on success: Use
mattermost:notify:successon theafter('deploy:success', ...)hook. - Notify on failure: Use
mattermost:notify:failureon theafter('deploy:failed', ...)hook.
- Notify at start of deployment: Use
Deploy a Laravel project using the Laravel recipe
masterTo use the pre-configured Laravel deployment workflow, include the Laravel recipe in your deployment script using
require 'recipe/laravel.php';.The
deploytask for Laravel includes several automated steps:- Preparation:
deploy:prepare(includesdeploy:info,deploy:setup,deploy:lock,deploy:release,deploy:update_code,deploy:env,deploy:shared, anddeploy:writable). - Dependencies:
deploy:vendorsinstalls composer dependencies. - Laravel Specifics:
artisan:storage:link(creates symbolic links),artisan:optimize(caches bootstrap files), andartisan:migrate(runs database migrations). - Publishing:
deploy:publish(includesdeploy:symlink,deploy:unlock, anddeploy:cleanup). - Post-deployment:
artisan:reload(reloads running services).
require 'recipe/laravel.php';- Preparation:
Upgrade from 5.x to 6.x
masterBranch Option Priority
In v6, if a host has a
branch(...)parameter, the--branchCLI 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
runandrunLocallynow return astringinstead of aDeployer\Type\Resultobject.- Replace
run('...')->toString()withrun('...'). - Replace
run('...')->toBool()withtest('...').
- Replace
env_varsis renamed toenv.set('env_vars', 'FOO=bar')$\rightarrow$set('env', ['FOO' => 'bar']).- If using the Symfony recipe, use
set('symfony_env', 'prod')instead ofset('env', 'prod').
Use the Writable Recipe
masterTo enable the writable directory management features in your deployment, include the writable recipe in your
deploy.phpfile.This recipe provides configuration options to manage directory permissions (via
chown,chgrp,chmod,acl, etc.) and adeploy:writabletask to apply these permissions.require 'recipe/deploy/writable.php';