composer require deployer/deployer --dev
Once installed, a deploy.php configuration file will be generated in the project root directory. This file will be used to define deployment rules and tasks.
<?php
require 'vendor/autoload.php';
require 'recipe/common.php';
// Server configuration
server('production', 'your_server_address')
->user('your_username')
->password('your_password')
->set('deploy_path', '/var/www/html/your_project_path');
// Project settings
set('repository', 'your_git_repository');
set('shared_files', ['.env']);
set('shared_dirs', ['storage']);
set('writable_dirs', ['bootstrap/cache']);
set('keep_releases', 5);
// Build task
task('build', function () {
run('cd {{release_path}} && build-script');
});
// Unlock if deploy fails
after('deploy:failed', 'deploy:unlock');
// Custom task: reload PHP-FPM
task('reload:php-fpm', function () {
run('sudo systemctl reload php-fpm');
});
// Deployment hooks
before('deploy', 'build');
after('deploy', 'reload:php-fpm');
Make sure to replace placeholders such as server address, username, and repository URL with values from your actual project environment.
dep deploy
This command will fetch the latest code from your Git repository, copy it to the specified server directory, and execute the defined automation tasks. The entire process is fast, reliable, and fully repeatable.
dep rollback
Deployer will switch to the previously deployed release and re-run the necessary automation steps to ensure the project is restored correctly.