Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Envoy Laravel Package

laravel/envoy

Laravel Envoy is a lightweight SSH task runner for defining and executing remote server tasks using a clean Blade-style syntax. Ideal for deployments, running Artisan commands, and other repeatable server automation workflows across multiple hosts.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require laravel/envoy --dev
    

    Add the envoy.php config file via:

    php artisan vendor:publish --provider="Laravel\Envoy\EnvoyServiceProvider"
    
  2. First Use Case: Create a Envoy.blade.php file in your project root (or specify a custom path in envoy.php). Define a simple task:

    @servers(['web' => ['host' => 'your-server.com']])
    
    @task('deploy', ['on' => 'web'])
        cd /path/to/your/app
        git pull origin main
        composer install --no-dev --optimize-autoloader
        php artisan optimize
    @endtask
    

    Run it via:

    php artisan envoy deploy
    
  3. Where to Look First:


Implementation Patterns

Core Workflows

  1. Task Organization:

    • Group related tasks into logical blocks (e.g., @task('deploy:database'), @task('deploy:code')).
    • Use @servers to define environments (e.g., staging, production) with host-specific configurations:
      @servers([
          'staging' => ['hosts' => ['staging.example.com']],
          'production' => ['hosts' => ['prod.example.com'], 'options' => ['port' => 2222']]
      ])
      
  2. Reusable Task Logic:

    • Extract common patterns into partials (e.g., _deploy-steps.blade.php):
      @include('_deploy-steps')
      
    • Use @env directives to conditionally include logic:
      @env('production')
          php artisan cache:clear
      @endenv
      
  3. Artisan Integration:

    • Run Laravel commands remotely:
      @task('migrate', ['on' => 'web'])
          php artisan migrate --force
      @endtask
      
    • Pass arguments dynamically:
      php artisan envoy migrate --env=production -- --seed
      
  4. Parallel Execution:

    • Run tasks concurrently across servers:
      @parallel
          @servers(['web-1' => ['host' => 'server1.com']])
          @task('restart-queue')
              php artisan queue:restart
          @endtask
      
          @servers(['web-2' => ['host' => 'server2.com']])
          @task('restart-queue')
              php artisan queue:restart
          @endtask
      @endparallel
      
  5. Environment Variables:

    • Use .env variables in tasks:
      @task('deploy')
          cd {{ env('DEPLOY_PATH') }}
          git pull origin {{ env('BRANCH', 'main') }}
      @endtask
      
  6. Hooks for Pre/Post Actions:

    • Use @before and @after to wrap tasks:
      @task('deploy', ['on' => 'web'])
          @before
              echo "Starting deployment..."
          @endbefore
      
          git pull origin main
          composer install
      
          @after
              echo "Deployment complete!"
              php artisan down --releases
          @endafter
      @endtask
      
  7. Custom SSH Options:

    • Override SSH defaults per server or task:
      @servers(['web' => ['host' => 'server.com', 'options' => ['user' => 'deploy', 'key' => '~/.ssh/id_rsa']]])
      
  8. Local Development Proxy:

    • Use laravel/valet or laravel/homestead with Envoy for local task execution:
      @servers(['local' => ['host' => 'homestead.app']])
      

Integration Tips

  1. CI/CD Pipelines:

    • Trigger Envoy tasks from GitHub Actions, GitLab CI, or CircleCI:
      # Example GitHub Actions step
      - name: Deploy
        run: php artisan envoy deploy --env=production
      
  2. Composer Scripts:

    • Add Envoy tasks to composer.json:
      {
          "scripts": {
              "deploy": "envoy deploy --env=production"
          }
      }
      
      Run with:
      composer deploy
      
  3. Laravel Forge/Panel:

    • Use Envoy to extend Forge/Panel deploy hooks by creating custom scripts in your repo.
  4. Monitoring:

    • Log task output to a file for debugging:
      @task('deploy')
          @before
              echo "=== DEPLOY STARTED ===" >> /tmp/deploy.log
          @endafter
      
  5. Docker Integration:

    • Execute tasks inside containers:
      @task('docker:restart')
          docker-compose restart web
      @endtask
      

Gotchas and Tips

Pitfalls

  1. Blade Syntax Conflicts:

    • Avoid naming tasks/files with Blade-like names (e.g., if.blade.php) to prevent parsing errors.
    • Use @verbatim for raw SSH commands with special characters:
      @verbatim
          echo "This is a literal command with @symbols"
      @endverbatim
      
  2. Timeouts:

    • Default timeout is 30 seconds. Increase for slow servers:
      @servers(['slow' => ['host' => 'server.com', 'timeout' => 120]])
      
    • Or globally in envoy.php:
      'timeout' => 60,
      
  3. SSH Key Management:

    • Ensure SSH keys are properly configured. Use ~/.ssh/id_rsa by default, but specify custom paths:
      @servers(['web' => ['host' => 'server.com', 'key' => '~/.ssh/custom_key']])
      
    • For agent forwarding, use:
      @servers(['web' => ['host' => 'server.com', 'options' => ['-A']]])
      
  4. Permission Issues:

    • Tasks run as the SSH user (default: current system user). Use sudo carefully:
      @task('sudo-task')
          sudo chmod -R 755 /path/to/app
      @endtask
      
    • Prefer setfacl or configure permissions via deployment scripts.
  5. Variable Scope:

    • Variables defined in @servers are not automatically available in tasks. Pass them explicitly:
      @servers(['web' => ['host' => 'server.com', 'deploy_path' => '/var/www/app']])
      @task('deploy')
          cd {{ $deploy_path }}
      @endtask
      
  6. Parallel Task Quirks:

    • @parallel tasks run independently. Avoid shared state (e.g., modifying the same file).
    • Order of execution is not guaranteed.
  7. Debugging:

    • Enable verbose output with -v:
      php artisan envoy deploy -v
      
    • Use @echo for debugging:
      @task('debug')
          @echo "Current directory: $(pwd)"
      @endtask
      
  8. Windows Line Endings:

    • Ensure tasks use LF line endings (Linux/Unix). Convert files with:
      dos2unix Envoy.blade.php
      

Tips

  1. Task Templates:

    • Start with a template for common deployments:
      @servers(['web' => ['host' => 'server.com', 'deploy_path' => '/var/www/app']])
      
      @task('deploy', ['on' => 'web'])
          cd {{ $deploy_path }}
          git pull origin {{ env('BRANCH', 'main') }}
          composer install --no-dev --optimize-autoloader
          php artisan config:cache
          php artisan route:cache
          php artisan view:cache
          touch storage/framework/cache/data/cache_tags
      @endtask
      
  2. Dry Runs:

    • Test tasks locally with ssh flags:
      php artisan envoy deploy --env=production --ssh="ssh -vvv"
      
  3. Environment-Specific Files:

    • Use Envoy.blade.staging.php or `Envoy.blade.pro
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport