Installation
composer require bugbyte/deployer
Add the package to your composer.json under require.
Basic Configuration
Create a deploy.php file in your project root with a minimal setup:
<?php
require __DIR__.'/vendor/autoload.php';
use Bugbyte\Deployer\Deployer;
$deployer = new Deployer([
'local' => [
'path' => __DIR__,
],
'remote' => [
'host' => 'your-server.com',
'user' => 'deploy-user',
'path' => '/var/www/your-project',
],
]);
$deployer->deploy();
First Deployment Run the deployer via CLI:
php deploy.php
The package will:
rsync (excluding data_dirs by default).storage, uploads) outside the project root.production pointing to the new deployment directory.data_dirs in your deploy.php:
$deployer = new Deployer([
'local' => [
'path' => __DIR__,
'data_dirs' => ['storage', 'public/uploads'],
],
// ... rest of config
]);
php deploy.php
The package handles:
storage and uploads to /var/www/your-project/data/ on the server.public/uploads → symlink to /var/www/your-project/data/uploads).Pre-Deployment Hooks
Use preDeploy() to run migrations or build assets:
$deployer->setPreDeploy(function () {
shell_exec('php artisan migrate --force');
shell_exec('npm run production');
});
Post-Deployment Tasks
Use postDeploy() to clear caches or send notifications:
$deployer->setPostDeploy(function () {
shell_exec('php artisan cache:clear');
shell_exec('php artisan config:clear');
});
Rollback Strategy Automate rollbacks in CI/CD pipelines:
$deployer->setPostRollback(function () {
shell_exec('php artisan optimize:clear');
});
Environment Configuration
Override .env during deployment:
$deployer->setPreDeploy(function () {
file_put_contents(
__DIR__.'/remote/.env',
str_replace('APP_ENV=local', 'APP_ENV=production', file_get_contents(__DIR__.'/remote/.env'))
);
});
Artisan Commands Chain Laravel commands with deployment steps:
$deployer->setPreActivate(function () {
shell_exec('php artisan queue:work --daemon');
});
Storage Symlinks
Ensure storage/link runs post-deploy:
$deployer->setPostDeploy(function () {
shell_exec('php artisan storage:link');
});
SSH Config
Use ~/.ssh/config to avoid password prompts:
Host your-server.com
User deploy-user
IdentityFile ~/.ssh/id_rsa
Rsync Excludes
Customize excludes in deploy.php:
$deployer->setRsyncExcludes(['node_modules', '.git', 'vendor']);
Incremental Deploys
Leverage --copy-dest for faster subsequent deploys (handled automatically by the package).
Symlink Permissions
public/uploads).FollowSymLinks is enabled in Apache or symlinks are allowed in Nginx:
<Directory /var/www/your-project>
Options FollowSymLinks
</Directory>
Data Directory Ownership
data_dirs (e.g., storage) have incorrect permissions.chown -R www-data:www-data /var/www/your-project/data post-deploy.Rsync Overwriting
.env) are overwritten during deploy.deploy.php:
$deployer->setRsyncExcludes(['.env']);
Rollback Failures
production symlink is broken.$deployer->setPreRollback(function () {
if (!file_exists('/var/www/your-project/production')) {
throw new Exception('Symlink missing!');
}
});
Dry Runs Test deployments without uploading:
php deploy.php --dry-run
Verbose Output Enable debug mode:
$deployer = new Deployer([...], ['debug' => true]);
SSH Debugging
Use -vvv with rsync:
$deployer->setRsyncOptions(['-vvv']);
Custom Remote Commands Extend the deployer with SSH commands:
$deployer->addRemoteCommand('composer install --no-dev --optimize-autoloader');
Database Migrations
Integrate with LemonWeb/dbpatcher:
$deployer->setPreActivate(function () {
shell_exec('php vendor/bin/dbpatcher patch');
});
Slack/Email Notifications
Hook into postDeploy/postRollback:
$deployer->setPostDeploy(function () {
shell_exec('curl -X POST -H "Content-type: application/json" --data \'{"text":"Deployed successfully!"}\' YOUR_SLACK_WEBHOOK');
});
Path Handling
remote.path to avoid issues with rsync./var/www/your-project instead of ~/projects/your-project.PHP CLI Version
php -v
Case Sensitivity
data_dirs exactly (e.g., Storage vs storage).Optimized Deployment Workflow Combine with Laravel Forge/Envoyer for zero-downtime deploys:
$deployer->setPreActivate(function () {
shell_exec('php artisan down');
});
$deployer->setPostActivate(function () {
shell_exec('php artisan up');
});
Queue Workers Restart queue workers post-deploy:
$deployer->setPostDeploy(function () {
shell_exec('pkill -f "php artisan queue:work" && php artisan queue:work --daemon');
});
Horizon Integration For Laravel Horizon, include:
$deployer->setPostDeploy(function () {
shell_exec('php artisan horizon:terminate');
shell_exec('php artisan horizon:start');
});
How can I help you explore Laravel packages today?