如何解决异常在 laravel 5.5 中在生产中运行 Dusk 是不安全的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49622200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:35:24  来源:igfitidea点击:

How to solve Exception It is unsafe to run Dusk in production in laravel 5.5?

phplaravellaravel-5.5laravel-dusk

提问by Samira kalantari

I upgrated my project from laravel 5.4 to laravel 5.5 ,

我将我的项目从 laravel 5.4 升级到 laravel 5.5 ,

I dont have any problem in local env but in server i get this exception ,

我在本地环境中没有任何问题,但在服务器中我收到此异常,

I searched a lot and i know this issue may be duplicated but no solutions solved my problem!

我搜索了很多,我知道这个问题可能是重复的,但没有解决方案解决我的问题!

How can i not registering dusk when environment is production?

环境生产时如何不注册黄昏?

i wrote this code in AppServiceProvider.php :

我在 AppServiceProvider.php 中写了这段代码:

public function register()
{
    // Dusk, if env is appropriate
    if ($this->app->environment('local', 'testing')) {
        $this->app->register(DuskServiceProvider::class);
    }
}

but it seems not working. can anyone help?

但它似乎不起作用。有人可以帮忙吗?

EDITED : my composer.json file:

编辑:我的 composer.json 文件:

 "require-dev": {
    "filp/whoops": "~2.0",
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "1.*",
    "phpunit/phpunit": "^7.0.3",
    "symfony/css-selector": "4.0.*",
    "symfony/dom-crawler": "4.0.0",
    "barryvdh/laravel-ide-helper": "^2.4",
    "laravel/dusk": "^2.0"
  },

The Exception is :

例外是:

Exception
It is unsafe to run Dusk in production.

回答by CUGreen

In Laravel 5.5, packages are automatically discovered and loaded so you will probably need to tell it not to load dusk.

在 Laravel 5.5 中,包会被自动发现和加载,所以你可能需要告诉它不要加载 dusk。

One way is to add this to your composer.json

一种方法是将其添加到您的 composer.json

"extra": {
    "laravel": {
        "dont-discover": [
            "laravel/dusk"
        ]
    }
},

Also, you can add it to your dev dependencies and when you deploy in production, use:

此外,您可以将其添加到开发依赖项中,并在生产中部署时,使用:

composer install --no-dev

Taylor wrote an article about it here.

泰勒在这里写了一篇关于它的文章。

回答by Adam Kozlowski

Look, it does not work because it is configured to work on localand testingenvironment. I guess that you need to add 'production' (if your production is called 'production in your .envfile environment:

看,因为它被配置为工作不工作localtesting环境。我想您需要添加“生产”(如果您的生产在您的.env文件环境中被称为“生产” :

AppServiceProvider

应用服务提供者

public function register()
{
    // Dusk, if env is appropriate
    if ($this->app->environment('local', 'testing', 'production')) {
        $this->app->register(DuskServiceProvider::class);
    }
}

When installing to production server I just needed to use the --no-devflag

安装到生产服务器时,我只需要使用--no-dev标志

composer install --no-dev

Good luck!

祝你好运!

回答by Thilina Dharmasena

Check whether file which named .envcontained in the source folder and setup Database user name and password and other settings.

检查.env源文件夹中是否包含命名的文件,并设置数据库用户名和密码等设置。

I had the same problem because I have set all the things but forgot to change the .env.exampleto .env

我遇到了同样的问题,因为我已经设置了所有的东西,但忘记将其更改.env.example.env

回答by Chrisjan

If you're experiencing this problem while in a developing environmentand accidentally landed here due to the title, you should check that your .envfile is set up for development. It should contain the line

如果您在开发环境中遇到此问题并由于标题而意外登陆这里,您应该检查您的.env文件是否已设置用于开发。它应该包含该行

APP_ENV=local

APP_ENV=local

Here is an example of how the .envfile could look: https://github.com/laravel/laravel/blob/master/.env.example

以下是.env文件外观的示例:https: //github.com/laravel/laravel/blob/master/.env.example

And here is the Laravel documentation: https://laravel.com/docs/5.7/configuration

这是 Laravel 文档:https://laravel.com/docs/5.7/configuration



Also, in composer.json, laravel/duskshould be listed under require-devand not require.

此外,在composer.json,laravel/dusk应该列在 下require-dev而不是require