Laravel 5: run migrations on server environment, not local

懵懂的女人 提交于 2019-12-04 12:37:09

You can't run any remote commands on your local artisan. Anything you run there will only work locally (even if you set the ENV variable).

Setting the ENV variable is just to tell the application to behave as if it is in that environment. But doesn't tell artisan to use the remote production environment.

If you want to run commands on your production server, I suggest you look into Envoy. It is a completely standalone project (and does not have to be used only with Laravel projects) and is specifically for deployment.

It is basically a thin wrapper around SSHing into your remote server and then running commands. An example Envoy.blade.php file on my sites might look like this:

@servers(['web' => 'account@server'])

@task('deploy')
    cd ~/src

    php artisan down
    git pull origin master

    composer install --no-dev --no-progress --prefer-dist
    php artisan migrate --force --no-interaction
    php artisan optimize
    php artisan up
@endtask

This SSHes in, puts the application in maintenance mode, pulls the new code, does the various 'new code' setups like composer install, migrate, etc. and then pulls the application out of maintenance mode.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!