hetemlというレンタルサーバーにLaravelをDeployerでデプロイしたときの設定
Laravelを使うレベル感の人はAWSなどが多いだろうと思いますが
hetemlというレンタルサーバーの情報は少ないので記しておきます。
deploy.php
<?php
namespace Deployer;
// vendor/bin/dep deploy production
require 'recipe/laravel.php';
// require 'recipe/npm.php';
// Config
// Project name
set('application', 'super_cms');
set('repository', 'git@github.com:sasasa/super_cms.git');
set('git_tty', false);
set('release_use_sudo', false);
// set('use_sudo', false);
add('shared_files', ['.env']);
add('shared_dirs', ['storage']);
// Writable dirs by web server
add('writable_dirs', ['bootstrap/cache', 'storage']);
// add('writable_dirs', []);
set('allow_anonymous_stats', true);
set('deploy_path', '/home/users/2/sasasasa/{{application}}');
set('release_name', function () {
return (string) run('date +"%Y%m%d%H%M%S"');
});
// Hosts
host('ssh-sasasasa.heteml.net')
->IdentityFile('~/.ssh/bitbucket/id_rsa')
->stage('production')
->user('sasasasa')
->set('http_user', 'HetemlUser')
->set('deploy_path', '/home/users/2/sasasasa/{{application}}')
->port(2222)
->set('branch', 'main')
->addSshOption('StrictHostKeyChecking', 'no')
->addSshOption('UserKnownHostsFile', '/dev/null')
->set('writable_use_sudo', false)
->set('writable_mode', 'chmod')
->set('shell', '/bin/bash -ls');
// Tasks
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:vendors',
'deploy:writable',
'artisan:storage:link',
'artisan:view:cache',
'artisan:config:cache',
// 'artisan:optimize',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]);
task('build', function () {
run('cd {{release_path}} && build');
});
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// shared/.envを.env.{stage}で上書きする
task('overwrite-env', function () {
$stage = get('stage');
$src = ".env.${stage}";
$deployPath = get('deploy_path');
$sharedPath = "${deployPath}/shared";
run("cp -f {{release_path}}/${src} ${sharedPath}/.env");
});
after('deploy:shared', 'overwrite-env');
// Migrate database before symlink new release.
before('deploy:symlink', 'artisan:migrate');