|
| 1 | +# Basic configurations |
| 2 | + |
| 3 | +Following the instructions on the README page: |
| 4 | + |
| 5 | +```bash |
| 6 | +# install |
| 7 | +composer require lorisleiva/laravel-deployer |
| 8 | + |
| 9 | +# initialize configurations |
| 10 | +php artisan deploy:init |
| 11 | +``` |
| 12 | + |
| 13 | +You should end up with a `deploy.php` file at the root of your project. |
| 14 | + |
| 15 | +**:fire: Pro tips:** |
| 16 | +* Runing `php artisan deploy your.hostname.com -a`, will set you up with everything without asking you any questions. |
| 17 | +* Using the `-f` option will optimize the configuration file for servers that are maintained by Laravel Forge. |
| 18 | +* You can combine the two above. |
| 19 | + |
| 20 | +Before starting you first deployment, you should go check your `deploy.php` file to make sure it suits your deployment flow. |
| 21 | + |
| 22 | +## Check the options |
| 23 | + |
| 24 | +```php |
| 25 | +// The name of your application |
| 26 | +set('application', 'Your Application Name'); |
| 27 | + |
| 28 | +// The repository of your application |
| 29 | +set('repository', 'ssh://git@bitbucket.org/vendor/repository.git'); |
| 30 | + |
| 31 | +// Whether or not you allow Deployer to receive anonymous statistics from you. |
| 32 | +set('allow_anonymous_stats', false); |
| 33 | + |
| 34 | +// Allocate TTY for git clone command. |
| 35 | +set('git_tty', true); |
| 36 | + |
| 37 | +// Default shared files are: `.env`. You can add more here. |
| 38 | +add('shared_files', []); |
| 39 | + |
| 40 | +// Default shared directories are: `storage`. You can add more here. |
| 41 | +add('shared_dirs', []); |
| 42 | + |
| 43 | +// Default writable directories are: |
| 44 | +// `bootstrap/cache`, |
| 45 | +// `storage`, |
| 46 | +// `storage/app`, |
| 47 | +// `storage/app/public`, |
| 48 | +// `storage/framework`, |
| 49 | +// `storage/framework/cache`, |
| 50 | +// `storage/framework/sessions`, |
| 51 | +// `storage/framework/views`, |
| 52 | +// `storage/logs` |
| 53 | +// You can add more here. |
| 54 | +add('writable_dirs', []); |
| 55 | +``` |
| 56 | + |
| 57 | +* Run `php artisan deploy:configs` to see all options and their value. |
| 58 | +* [Check out all available options](docs/all-options.md) |
| 59 | + |
| 60 | + |
| 61 | +## Check the hosts |
| 62 | + |
| 63 | +```php |
| 64 | +// If you have more than one stage, you can define the default stage here. |
| 65 | +set('default_stage', 'prod'); |
| 66 | + |
| 67 | +// Your hostname can be a domain or an IP address. |
| 68 | +host('your.hostname.com') |
| 69 | + |
| 70 | + // (Optional) The stage of your host. |
| 71 | + // Can be useful to distinguish a production server and a staging server. |
| 72 | + ->stage('prod') |
| 73 | + |
| 74 | + // The deploy path. Where you code is. |
| 75 | + ->set('deploy_path', '/var/www/html/your.hostname.com') |
| 76 | + |
| 77 | + // (Optional) Who should Deployer connect as during deployment. |
| 78 | + ->user('root'); |
| 79 | +``` |
| 80 | + |
| 81 | +* By default, Deployer will access your server via SSH as the provided user. |
| 82 | +* More authentication methods can be found [here](host-configuration). |
| 83 | + |
| 84 | + |
| 85 | +## Check the tasks and the hooks |
| 86 | + |
| 87 | +Laravel Deployer already defines the main `deploy` task, therefore it is not visible in your `deployer.php` file. |
| 88 | +If you just need to add more tasks before or after some other tasks, you can use hooks: |
| 89 | + |
| 90 | +```php |
| 91 | +before('existing:task', 'mycustom:task'); |
| 92 | +after('mycustom:task', 'myscustom:secondtask'); |
| 93 | +``` |
| 94 | + |
| 95 | +* [Check out how to create you custom tasks and use hooks](custom-tasks). |
| 96 | +* [Check out all available tasks](all-tasks). |
| 97 | + |
| 98 | +If some of the tasks used by default during deployment are unecessary for you or you need to redefine the deployment flow completely, you can override the `deploy` task: |
| 99 | + |
| 100 | +```php |
| 101 | +// This is the default definition of the `deploy` task. |
| 102 | +// Copy/paste it in your `deploy.php` file if you want complete control over it. |
| 103 | +desc('Deploy your project'); |
| 104 | +task('deploy', [ |
| 105 | + 'deploy:info', |
| 106 | + 'deploy:prepare', |
| 107 | + 'deploy:lock', |
| 108 | + 'deploy:release', |
| 109 | + 'deploy:update_code', |
| 110 | + 'firstdeploy:shared', |
| 111 | + 'deploy:shared', |
| 112 | + 'deploy:vendors', |
| 113 | + 'deploy:writable', |
| 114 | + 'artisan:storage:link', |
| 115 | + 'artisan:view:clear', |
| 116 | + 'artisan:cache:clear', |
| 117 | + 'artisan:config:cache', |
| 118 | + 'artisan:optimize', |
| 119 | + 'deploy:symlink', |
| 120 | + 'deploy:unlock', |
| 121 | + 'cleanup', |
| 122 | +]); |
| 123 | + |
| 124 | +after('deploy:failed', 'deploy:unlock'); |
| 125 | +after('deploy', 'success'); |
| 126 | +``` |
| 127 | + |
| 128 | +**:fire: Pro tips:** |
| 129 | +* Run `php artisan deploy:dump deploy` to display the tree of tasks that are executed during deployment including the ones added via hooks. |
| 130 | +* Note that this command can do that for any given task `php artisan deploy:dump mycustom:task`. |
0 commit comments