How to deploy Laravel

2019-01-24  本文已影响13人  积_渐

本机安装deploy

phar存档安装

curl -LO https://deployer.org/deployer.phar
mv deployer.phar /usr/local/bin/dep
chmod +x /usr/local/bin/dep

切换到项目中

dep init -t Laravel

此时会在你本地的laravel项目根目录新建一个deploy.php的文件

接下来修改该文件:

<?php
namespace Deployer;

require 'recipe/laravel.php'; //次文件可以安装在项目中  也可以在本地机器中

// Project name
set('application', '项目名称');

// Project repository
set('repository', 'git地址');

// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);

set('writable_mode', 'chown'); //dep deploy运行后报写权限错误时添加此行代码Executing task deploy:writable Unable to setup correct permissions for writable dirs. You need to configure sudo's sudoers files to not prompt for password, or setup correct permissions manually.

// Shared files/dirs between deploys 
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server 
add('writable_dirs', []);


// Hosts

host('服务器ip')
    ->user('root')
    ->port(22)
    ->identityFile('~/.ssh/id_rsa')
    ->set('deploy_path', '将要部署到的位置/项目名称'); //绝对路径
    
// Tasks

task('build', function () {
    run('cd 将要部署到的位置/项目名称 && build');
});

task('deploy', [
    'deploy:info',
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:update_code',
    'deploy:shared',
    'deploy:vendors',
    'deploy:writable',
    'artisan:storage:link',
    'artisan:view:clear',
    'artisan:cache:clear',
//    'artisan:config:cache', //dep deploy 时报artisan config:cache错误时  将该句注释
    'artisan:optimize',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
]);

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.

//before('deploy:symlink', 'artisan:migrate');

在本地项目中运行dep deploy即可

上一篇下一篇

猜你喜欢

热点阅读