Laravel 5:在服务器环境而不是本地环境上运行迁移 [英] Laravel 5: run migrations on server environment, not local

查看:157
本文介绍了Laravel 5:在服务器环境而不是本地环境上运行迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Laravel 5应用程序中创建了一组简单的数据库迁移,它们可以在我的本地开发环境中很好地运行.

I have a simple set of database migrations created within my Laravel 5 application, and they run nicely on my local development environment.

现在该运行我的新生产服务器环境上的迁移了.我已经配置了数据库连接并部署了该应用程序,该应用程序可以看到数据库,但是没有表-因此需要运行迁移.

Now its time to run to run the migration on my new production server environment. I have configured the DB connection and deployed the app, and the app sees the database, but there are no tables - so migrations need to be run.

我相信,以下命令应使用生产"环境运行迁移,该环境是通过远程数据库连接详细信息设置的:

The following command, I believe, should run the migrations using the "production" environment, which is set up with the remote DB connection details:

php artisan --env=production migrate 

该迁移有效,但可以在本地环境上运行!这是我的生产环境的环境文件(使用Amazon Elastic beantalk服务):

The migration works, but it runs on the local environment! Here is the environment file for my production environment(using amazon elastic beanstalk service) :

.elasticbeanstalk.env

.elasticbeanstalk.env

APP_ENV=production
APP_DEBUG=true
APP_URL=<myappname.elasticbeanstalk.com>

DB_HOST=<myapp.amazonserveraddress.amazonaws.com:3306>
DB_DATABASE=<mydbname>
DB_USERNAME=<mydbusername>
DB_PASSWORD=<mydbpassword>

因此我的环境文件配置不正确,或者工匠无法切换到该环境.我可以更改.env文件(本地开发环境,称为本地")以连接到远程生产数据库,但是我想正确使用Laravels环境.

So either my environment file is not configured correctly, or artisan is not able to switch to that environment. I could change my .env file (local development environment, named "local") to connect to the remote, production DB, but I want to properly use Laravels environments.

我想念什么?为什么迁移总是在本地"上运行?

What am I missing? Why does the migration always run on "local"?

谢谢.

推荐答案

您不能在本地artisan上运行任何远程命令.在此运行的任何内容都只能在本地运行(即使您设置了ENV变量).

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).

设置ENV变量只是为了告诉应用程序在该环境中的行为.但是不要告诉工匠使用远程生产环境.

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.

如果要在生产服务器上运行命令,建议您查看 Envoy .这是一个完全独立的项目(不必仅与Laravel项目一起使用),并且专门用于部署.

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.

基本上,它是将SSH SSH到远程服务器然后运行命令的一个精简包装.我网站上的Envoy.blade.php示例文件可能如下所示:

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

此SSH进入,将应用程序置于维护模式,提取新代码,执行各种新代码"设置(例如composer安装,迁移等),然后将应用程序退出维护模式.

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.

这篇关于Laravel 5:在服务器环境而不是本地环境上运行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆