「Php/deploy/deployer/laravel」の版間の差分
提供: 初心者エンジニアの簡易メモ
行39: | 行39: | ||
// /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service | // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service | ||
run('sudo systemctl restart php-fpm.service'); | run('sudo systemctl restart php-fpm.service'); | ||
+ | }); | ||
+ | after('deploy:symlink', 'php-fpm:restart'); | ||
+ | |||
+ | // [Optional] if deploy fails automatically unlock. | ||
+ | after('deploy:failed', 'deploy:unlock'); | ||
+ | |||
+ | // Migrate database before symlink new release. | ||
+ | |||
+ | before('deploy:symlink', 'artisan:migrate'); | ||
+ | </pre> | ||
+ | |||
+ | ==サンプルdeploy== | ||
+ | <pre> | ||
+ | namespace Deployer; | ||
+ | require 'recipe/laravel.php'; | ||
+ | |||
+ | // Configuration | ||
+ | |||
+ | set('ssh_type', 'native'); | ||
+ | set('ssh_multiplexing', true); | ||
+ | |||
+ | set('repository', 'git@bitbucket.org:kajimura/laraveltest.git'); | ||
+ | |||
+ | add('shared_files', ['.env']); | ||
+ | set('shared_dirs', [ | ||
+ | 'storage/app', | ||
+ | 'storage/framework/cache', | ||
+ | 'storage/framework/sessions', | ||
+ | 'storage/framework/views', | ||
+ | 'storage/logs' | ||
+ | ]); | ||
+ | |||
+ | add('writable_dirs', []); | ||
+ | |||
+ | // Servers | ||
+ | |||
+ | server('production', '158.199.143.204') | ||
+ | ->user('linux') | ||
+ | ->identityFile('~/.ssh/id_rsa') | ||
+ | ->set('deploy_path', '/var/www/laravel/laraveltest') | ||
+ | ->pty(true); | ||
+ | |||
+ | |||
+ | // Tasks | ||
+ | desc('Restart PHP-FPM service'); | ||
+ | task('php-fpm:restart', function () { | ||
+ | // The user must have rights for restart service | ||
+ | // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service | ||
+ | run('sudo /etc/rc.d/init.d/php-fpm restart'); | ||
}); | }); | ||
after('deploy:symlink', 'php-fpm:restart'); | after('deploy:symlink', 'php-fpm:restart'); |
2018年2月27日 (火) 23:12時点における版
インストール
php/deploy/deployer/基本 [ショートカット]
laravel用のdeployを用意
$ dep init [1 ] Laravel $ > 1
作成されたdeploy.phpのスケルトン
namespace Deployer; require 'recipe/laravel.php'; // Configuration set('ssh_type', 'native'); set('ssh_multiplexing', true); set('repository', 'git@domain.com:username/repository.git'); add('shared_files', []); add('shared_dirs', []); add('writable_dirs', []); // Servers server('production', 'domain.com') ->user('username') ->identityFile() ->set('deploy_path', '/var/www/domain.com') ->pty(true); // Tasks desc('Restart PHP-FPM service'); task('php-fpm:restart', function () { // The user must have rights for restart service // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service run('sudo systemctl restart php-fpm.service'); }); after('deploy:symlink', 'php-fpm:restart'); // [Optional] if deploy fails automatically unlock. after('deploy:failed', 'deploy:unlock'); // Migrate database before symlink new release. before('deploy:symlink', 'artisan:migrate');
サンプルdeploy
namespace Deployer; require 'recipe/laravel.php'; // Configuration set('ssh_type', 'native'); set('ssh_multiplexing', true); set('repository', 'git@bitbucket.org:kajimura/laraveltest.git'); add('shared_files', ['.env']); set('shared_dirs', [ 'storage/app', 'storage/framework/cache', 'storage/framework/sessions', 'storage/framework/views', 'storage/logs' ]); add('writable_dirs', []); // Servers server('production', '158.199.143.204') ->user('linux') ->identityFile('~/.ssh/id_rsa') ->set('deploy_path', '/var/www/laravel/laraveltest') ->pty(true); // Tasks desc('Restart PHP-FPM service'); task('php-fpm:restart', function () { // The user must have rights for restart service // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service run('sudo /etc/rc.d/init.d/php-fpm restart'); }); after('deploy:symlink', 'php-fpm:restart'); // [Optional] if deploy fails automatically unlock. after('deploy:failed', 'deploy:unlock'); // Migrate database before symlink new release. before('deploy:symlink', 'artisan:migrate');
deploy実行
$ dep deploy production ✔ Executing task deploy:prepare ✔ Executing task deploy:lock ✔ Executing task deploy:release ✔ Executing task deploy:update_code ✔ Executing task deploy:shared ✔ Executing task deploy:vendors ✔ Executing task deploy:writable ✔ Executing task artisan:view:clear ➤ Executing task artisan:cache:clear ✔ Executing task deploy:failed ✔ Executing task deploy:unlock
詳細を表示したいときは
dep deploy production -vvv
反映先の構成
├current -> ./releases/1 ├releases │ └1 │ ├app │ └composer.json 他など └shared ├storage └.env
currentに.envとstrageがlnで設定されてアプリの構成がそのまま入る。
releaseに初回成功するまではcurrentがreleaseとなったままとなる
xhprofのエラーが出るとき
gzip /etc/php.d/xhprof.ini
圧縮して設定から取り除く