Install the Bundle
Add to composer.json:
{
"require": {
"easycorp/easy-deploy-bundle": "^1.0"
}
}
Run composer require easycorp/easy-deploy-bundle.
Enable the Bundle
Add to config/bundles.php:
return [
// ...
EasyCorp\Bundle\EasyDeployBundle\EasyDeployBundle::class => ['all' => true],
];
Configure SSH Access
config/packages/easy_deploy.yaml:
easy_deploy:
servers:
production:
host: 'your-server.com'
user: 'deploy-user'
port: 22
private_key: '%kernel.project_dir%/path/to/private_key'
First Deployment Run the default deployer command:
php bin/console easy-deploy:deploy production
This will clone the repo, pull updates, and deploy with zero downtime.
config/packages/easy_deploy.yaml for server and deployment settings.easy_deploy.yaml.php bin/console easy-deploy:deploy production
Define Stages
Configure multiple environments (e.g., staging, production) in easy_deploy.yaml:
easy_deploy:
servers:
staging:
host: 'staging.example.com'
user: 'deploy'
production:
host: 'prod.example.com'
user: 'deploy'
Deploy to a Specific Stage
php bin/console easy-deploy:deploy staging
Sequential Deployments
Use a script or CI/CD pipeline to deploy to staging first, then promote to production:
php bin/console easy-deploy:deploy staging
# Test staging, then:
php bin/console easy-deploy:deploy production
Pre/Post Deployment Hooks Extend the deployer to run custom commands before/after deployment:
// src/EasyDeploy/CustomDeployer.php
namespace App\EasyDeploy;
use EasyCorp\Bundle\EasyDeployBundle\Deployer\DeployerInterface;
class CustomDeployer implements DeployerInterface
{
public function deploy()
{
// Pre-deployment: e.g., database migrations
$this->run('php bin/console doctrine:migrations:migrate --no-interaction');
// Call parent deploy logic
parent::deploy();
// Post-deployment: e.g., cache warmup
$this->run('php bin/console cache:clear');
}
}
Register the custom deployer in config/packages/easy_deploy.yaml:
easy_deploy:
deployer: App\EasyDeploy\CustomDeployer
Environment-Specific Configurations Use Symfony’s environment variables or parameter bags to customize deployments per stage:
# config/packages/easy_deploy_production.yaml
easy_deploy:
servers:
production:
# Override settings for production
deploy_path: '/var/www/production'
keep_releases: 5
Multi-Server Deployments Deploy to multiple servers simultaneously by defining an array of servers:
easy_deploy:
servers:
load_balancers:
- host: 'lb1.example.com'
user: 'deploy'
- host: 'lb2.example.com'
user: 'deploy'
Deploy to all load balancers:
php bin/console easy-deploy:deploy load_balancers
Git Strategies Customize Git operations (e.g., shallow clones, specific branches) in the deployer:
protected function cloneRepository()
{
$this->run('git clone --depth 1 --branch master git@github.com:user/repo.git ' . $this->getDeployPath());
}
Rollback Mechanism Leverage EasyDeploy’s release management to roll back:
php bin/console easy-deploy:rollback production 2023-01-01T12:00:00+00:00
SSH Connection Issues
easy_deploy.yaml. Use the Troubleshooting Guide.ssh -i %kernel.project_dir%/path/to/private_key deploy@your-server.com
File Permissions
chmod command in your deployer or use umask:
easy_deploy:
servers:
production:
deploy_path: '/var/www/prod'
chmod: '755'
Zero Downtime Deployments
current symlink. EasyDeploy handles this by default, but verify:
easy_deploy:
servers:
production:
symlink: 'current'
Large Repositories
protected function cloneRepository()
{
$this->run('git clone --depth 1 git@github.com:user/repo.git ' . $this->getDeployPath());
}
Private Key Paths
private_key in easy_deploy.yaml to avoid issues with Symfony’s kernel project directory resolution:
easy_deploy:
servers:
production:
private_key: '/home/user/.ssh/id_rsa'
Overriding Defaults
keep_releases, deploy_path) can be overridden globally or per server. Global overrides in easy_deploy.yaml take precedence over defaults:
easy_deploy:
keep_releases: 3 # Overrides default (5)
deploy_path: '/var/www/shared' # Overrides per-server deploy_path if not specified
Environment Variables
%env() for sensitive data (e.g., SSH keys):
easy_deploy:
servers:
production:
private_key: '%env(SSH_PRIVATE_KEY_PATH)%'
Custom Deployer Classes
Extend EasyCorp\Bundle\EasyDeployBundle\Deployer\AbstractDeployer to add custom logic:
namespace App\EasyDeploy;
use EasyCorp\Bundle\EasyDeployBundle\Deployer\AbstractDeployer;
class CustomDeployer extends AbstractDeployer
{
protected function getDeployPath()
{
return $this->getServer()->getDeployPath() . '/app';
}
protected function postDeploy()
{
$this->run('php bin/console cache:warmup');
}
}
Register in easy_deploy.yaml:
easy_deploy:
deployer: App\EasyDeploy\CustomDeployer
Event Listeners Use Symfony events to hook into the deployment lifecycle (e.g., trigger notifications):
// src/EventListener/DeployListener.php
namespace App\EventListener;
use EasyCorp\Bundle\EasyDeployBundle\Event\DeployEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class DeployListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
DeployEvent
How can I help you explore Laravel packages today?