1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

hetemlというレンタルサーバーにLaravelをDeployerでデプロイしたときの設定

Last updated at Posted at 2022-05-09

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');

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?