├── .github └── FUNDING.yml ├── .gitignore ├── README.md ├── deploy.php ├── deploy.yaml ├── episode-3 ├── deploy.php └── deploy.yaml ├── episode-4 ├── deploy.php └── deploy.yaml ├── episode-5 ├── deploy.yaml └── deploy │ ├── my-first-recipe.php │ └── webhook.php ├── episode-6 └── deploy.yaml └── episode-7 └── deploy.yaml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [lorisleiva] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.build/ 2 | /.idea/ 3 | /vendor/ 4 | /tests/fixtures/tmp/ 5 | .phpunit.result.cache 6 | composer.lock 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚀 Laravel Deployer 2 | 3 | > Looking for the old Laravel Deployer? [Click here](https://github.com/lorisleiva/laravel-deployer/tree/old). 4 | 5 | Laravel Deployer is no longer the package it used to be. Since that package was created, [Deployer](https://github.com/deployphp/deployer) has become better and better at integrating with Laravel to the point that I will now put my efforts into maintaining Deployer directly for Laravel users rather than mirroring its changes on a different repo after each release. You can [read more about this decision here](https://twitter.com/lorismatic/status/1376519608207867907?s=20). 6 | 7 | I've written a series of tutorials to help Laravel users deploy their application using Deployer directly. 8 | 9 | [Deploy your Laravel app from scratch](https://lorisleiva.com/deploy-your-laravel-app-from-scratch). 10 | 11 | If you prefer a quick guide to get started with Deployer 7, I've added one for you below. 12 | 13 | ## Deploy your Laravel application using Deployer 7 14 | 15 | - Add [Deployer](https://github.com/deployphp/deployer) to your dependencies. 16 | ```shell 17 | composer require deployer/deployer:^7.0 18 | ``` 19 | - Copy/paste the [`deploy.yaml`](./deploy.yaml) or [`deploy.php`](./deploy.php) file of this repository to the root of your project. 20 | - Update the `deploy.yaml` or `deploy.php` with your own server details. 21 | - Run `dep deploy` to deploy once. 22 | - Run `dep ssh` to connect to your server via SSH. 23 | - Run `cp .env.example .env && php artisan key:generate` to initialize your `.env` file. 24 | - Run `vim .env` and update your production environment variables. 25 | - Exit your server — `exit`. 26 | - Run `dep deploy` once more now that your `.env` file is all set up. 27 | -------------------------------------------------------------------------------- /deploy.php: -------------------------------------------------------------------------------- 1 | set('remote_user', 'root') 15 | ->set('hostname', 'mylaravelapp.com') 16 | ->set('deploy_path', '/var/www/{{hostname}}'); 17 | 18 | task('deploy', [ 19 | 'deploy:prepare', 20 | 'deploy:vendors', 21 | 'artisan:storage:link', 22 | 'artisan:view:cache', 23 | 'artisan:config:cache', 24 | 'artisan:migrate', 25 | 'npm:install', 26 | 'npm:run:prod', 27 | 'deploy:publish', 28 | 'php-fpm:reload', 29 | ]); 30 | 31 | task('npm:run:prod', function () { 32 | cd('{{release_or_current_path}}'); 33 | run('npm run prod'); 34 | }); 35 | 36 | after('deploy:failed', 'deploy:unlock'); 37 | -------------------------------------------------------------------------------- /deploy.yaml: -------------------------------------------------------------------------------- 1 | import: 2 | - recipe/laravel.php 3 | - contrib/php-fpm.php 4 | - contrib/npm.php 5 | 6 | config: 7 | application: 'mylaravelapp' 8 | repository: 'git@github.com:lorisleiva/mylaravelapp.git' 9 | php_fpm_version: '8.0' 10 | 11 | hosts: 12 | prod: 13 | remote_user: root 14 | hostname: mylaravelapp.com 15 | deploy_path: '/var/www/{{hostname}}' 16 | 17 | tasks: 18 | deploy: 19 | - deploy:prepare 20 | - deploy:vendors 21 | - artisan:storage:link 22 | - artisan:view:cache 23 | - artisan:config:cache 24 | - artisan:migrate 25 | - npm:install 26 | - npm:run:prod 27 | - deploy:publish 28 | - php-fpm:reload 29 | npm:run:prod: 30 | script: 31 | - 'cd {{release_or_current_path}} && npm run prod' 32 | 33 | after: 34 | deploy:failed: deploy:unlock 35 | -------------------------------------------------------------------------------- /episode-3/deploy.php: -------------------------------------------------------------------------------- 1 | set('remote_user', 'root') 15 | ->set('hostname', 'jollygood.app') 16 | ->set('deploy_path', '/var/www/{{hostname}}'); 17 | 18 | task('deploy', [ 19 | 'deploy:prepare', 20 | 'deploy:vendors', 21 | 'artisan:storage:link', 22 | 'artisan:view:cache', 23 | 'artisan:config:cache', 24 | 'artisan:migrate', 25 | 'npm:install', 26 | 'npm:run:prod', 27 | 'deploy:publish', 28 | 'php-fpm:reload', 29 | ]); 30 | 31 | task('npm:run:prod', function () { 32 | cd('{{release_path}}'); 33 | run('npm run prod'); 34 | }); 35 | 36 | after('deploy:failed', 'deploy:unlock'); 37 | -------------------------------------------------------------------------------- /episode-3/deploy.yaml: -------------------------------------------------------------------------------- 1 | import: 2 | - recipe/laravel.php 3 | - contrib/php-fpm.php 4 | - contrib/npm.php 5 | 6 | config: 7 | application: 'blog-jollygood' 8 | repository: 'git@github.com:lorisleiva/blog-jollygood.git' 9 | php_fpm_version: '8.0' 10 | 11 | hosts: 12 | prod: 13 | remote_user: root 14 | hostname: jollygood.app 15 | deploy_path: '/var/www/{{hostname}}' 16 | 17 | tasks: 18 | deploy: 19 | - deploy:prepare 20 | - deploy:vendors 21 | - artisan:storage:link 22 | - artisan:view:cache 23 | - artisan:config:cache 24 | - artisan:migrate 25 | - npm:install 26 | - npm:run:prod 27 | - deploy:publish 28 | - php-fpm:reload 29 | npm:run:prod: 30 | script: 31 | - 'cd {{release_path}} && npm run prod' 32 | 33 | after: 34 | deploy:failed: deploy:unlock 35 | -------------------------------------------------------------------------------- /episode-4/deploy.php: -------------------------------------------------------------------------------- 1 | set('remote_user', 'root') 15 | ->set('hostname', 'jollygood.app') 16 | ->set('deploy_path', '/var/www/{{hostname}}'); 17 | 18 | task('deploy', [ 19 | 'deploy:prepare', 20 | 'deploy:vendors', 21 | 'artisan:storage:link', 22 | 'artisan:view:cache', 23 | 'artisan:config:cache', 24 | 'artisan:migrate', 25 | 'npm:install', 26 | 'npm:run:prod', 27 | 'deploy:publish', 28 | 'php-fpm:reload', 29 | ]); 30 | 31 | task('npm:run:prod', function () { 32 | cd('{{release_or_current_path}}'); 33 | run('npm run prod'); 34 | }); 35 | 36 | after('deploy:failed', 'deploy:unlock'); 37 | -------------------------------------------------------------------------------- /episode-4/deploy.yaml: -------------------------------------------------------------------------------- 1 | import: 2 | - recipe/laravel.php 3 | - contrib/php-fpm.php 4 | - contrib/npm.php 5 | 6 | config: 7 | application: 'blog-jollygood' 8 | repository: 'git@github.com:lorisleiva/blog-jollygood.git' 9 | php_fpm_version: '8.0' 10 | 11 | hosts: 12 | prod: 13 | remote_user: root 14 | hostname: jollygood.app 15 | deploy_path: '/var/www/{{hostname}}' 16 | 17 | tasks: 18 | deploy: 19 | - deploy:prepare 20 | - deploy:vendors 21 | - artisan:storage:link 22 | - artisan:view:cache 23 | - artisan:config:cache 24 | - artisan:migrate 25 | - npm:install 26 | - npm:run:prod 27 | - deploy:publish 28 | - php-fpm:reload 29 | npm:run:prod: 30 | script: 31 | - 'cd {{release_or_current_path}} && npm run prod' 32 | 33 | after: 34 | deploy:failed: deploy:unlock 35 | -------------------------------------------------------------------------------- /episode-5/deploy.yaml: -------------------------------------------------------------------------------- 1 | import: 2 | - recipe/laravel.php 3 | - contrib/php-fpm.php 4 | - contrib/npm.php 5 | - deploy/my-first-recipe.php 6 | - deploy/webhook.php 7 | 8 | config: 9 | application: 'blog-jollygood' 10 | repository: 'git@github.com:lorisleiva/blog-jollygood.git' 11 | php_fpm_version: '8.0' 12 | webhook_url: 'https://octo.hk/DL8v1dKM4hinXhTWXIX8' 13 | 14 | hosts: 15 | prod: 16 | remote_user: root 17 | hostname: jollygood.app 18 | deploy_path: '/var/www/{{hostname}}' 19 | labels: 20 | mode: api 21 | 22 | tasks: 23 | deploy: 24 | - deploy:prepare 25 | - deploy:vendors 26 | - artisan:storage:link 27 | - artisan:view:cache 28 | - artisan:config:cache 29 | - artisan:migrate 30 | - npm:install 31 | - npm:run:prod 32 | - deploy:publish 33 | - php-fpm:reload 34 | npm:run:prod: 35 | script: 36 | - 'cd {{release_or_current_path}} && npm run prod' 37 | 38 | before: 39 | deploy: webhook:started 40 | 41 | after: 42 | deploy:success: webhook:successful 43 | deploy:failed: 44 | - deploy:unlock 45 | - webhook:failed 46 | -------------------------------------------------------------------------------- /episode-5/deploy/my-first-recipe.php: -------------------------------------------------------------------------------- 1 | setProgress(60); 30 | }); 31 | 32 | desc('Demo all prompting functions.'); 33 | task('app:input', function () { 34 | $fruit = ask("What's your favourite fruit?", 'strawberry'); 35 | writeln("You're favourite fruit is: $fruit"); 36 | 37 | $diet = askChoice("What's your diet?", ['Vegan', 'Vegeterian', 'Pescatarian', 'Carnivore'], 0); 38 | writeln("You're diet is: $diet"); 39 | 40 | $likesCooking = askConfirmation("Do you like cooking?", true); 41 | writeln($likesCooking ? "Hell yeah! Let's cook together!" : "No worries, I'll cook for you!"); 42 | 43 | $secretIngredient = askHiddenResponse("What's your secret ingredient?"); 44 | writeln("Your secret ingredient is safe with me."); 45 | }); 46 | 47 | set('should_prompt', true); 48 | 49 | desc('Demo bypassing prompts.'); 50 | task('app:bypass:prompt', function () { 51 | $shouldPrompt = get('should_prompt', true); 52 | $fruit = $shouldPrompt ? ask("What's your favourite fruit?", 'strawberry') : 'strawberry'; 53 | writeln("You're favourite fruit is: $fruit"); 54 | }); 55 | -------------------------------------------------------------------------------- /episode-5/deploy/webhook.php: -------------------------------------------------------------------------------- 1 | get('release_name'), 16 | 'application' => get('application'), 17 | ]; 18 | }); 19 | 20 | desc('Notify via webhook that the deployment started.'); 21 | task('webhook:started', sendWebhook('started')); 22 | 23 | desc('Notify via webhook that the deployment was successful.'); 24 | task('webhook:successful', sendWebhook('successful')); 25 | 26 | desc('Notify via webhook that the deployment failed.'); 27 | task('webhook:failed', sendWebhook('failed')); 28 | 29 | function sendWebhook(string $state) { 30 | return function () use ($state) { 31 | Httpie::post(get('webhook_url')) 32 | ->body(get('webhook_data', [])) 33 | ->header("X-Deployment-State: $state") 34 | ->send(); 35 | }; 36 | }; 37 | -------------------------------------------------------------------------------- /episode-6/deploy.yaml: -------------------------------------------------------------------------------- 1 | import: 2 | - recipe/laravel.php 3 | - contrib/php-fpm.php 4 | - contrib/npm.php 5 | 6 | config: 7 | application: 'blog-jollygood' 8 | repository: 'git@github.com:lorisleiva/blog-jollygood.git' 9 | php_fpm_version: '8.0' 10 | 11 | hosts: 12 | prod: 13 | remote_user: forge 14 | hostname: 'forge.jollygood.app' 15 | deploy_path: '~/{{hostname}}' 16 | 17 | tasks: 18 | deploy: 19 | - deploy:prepare 20 | - deploy:vendors 21 | - artisan:storage:link 22 | - artisan:view:cache 23 | - artisan:config:cache 24 | - artisan:migrate 25 | - npm:install 26 | - npm:run:prod 27 | - deploy:publish 28 | - php-fpm:reload 29 | npm:run:prod: 30 | script: 31 | - 'cd {{release_or_current_path}} && npm run prod' 32 | 33 | after: 34 | deploy:failed: deploy:unlock 35 | -------------------------------------------------------------------------------- /episode-7/deploy.yaml: -------------------------------------------------------------------------------- 1 | import: 2 | - recipe/laravel.php 3 | - contrib/php-fpm.php 4 | - contrib/npm.php 5 | 6 | config: 7 | application: 'blog-jollygood' 8 | repository: 'git@github.com:lorisleiva/blog-jollygood.git' 9 | php_fpm_version: '8.0' 10 | 11 | hosts: 12 | prod: 13 | remote_user: ploi 14 | hostname: 'ploi.jollygood.app' 15 | deploy_path: '~/{{hostname}}' 16 | 17 | tasks: 18 | deploy: 19 | - deploy:prepare 20 | - deploy:vendors 21 | - artisan:storage:link 22 | - artisan:view:cache 23 | - artisan:config:cache 24 | - artisan:migrate 25 | - npm:install 26 | - npm:run:prod 27 | - deploy:publish 28 | - php-fpm:reload 29 | npm:run:prod: 30 | script: 31 | - 'cd {{release_or_current_path}} && npm run prod' 32 | 33 | after: 34 | deploy:failed: deploy:unlock 35 | --------------------------------------------------------------------------------