php Laravel 5 如何从生产模式切换

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28719966/
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-08-26 00:01:43  来源:igfitidea点击:

Laravel 5 How to switch from Production mode

phplaravelartisan

提问by mikelovelyuk

When I run $ php artisan envI get;

当我跑步时,$ php artisan env我得到了;

Current application environment: production

How can I change this to development or something similar? So I can see errors.. I have read a lot of the documentationbut it is not at all easy for a newbie to understand. I don't have server config experience, really.

我如何将其更改为开发或类似的东西?所以我可以看到错误..我已经阅读了很多文档,但是对于新手来说理解起来并不容易。我真的没有服务器配置经验。

I'm sure there is "smart" way to do this, but all I am interested in, for now, is manually changing the environment. How do I do this?

我确信有“聪明”的方法可以做到这一点,但目前我感兴趣的只是手动改变环境。我该怎么做呢?

回答by Bogdan

Laravel 5 gets its enviroment related variables from the .envfile located in the root of your project. You just need to set APP_ENVto whatever you want, for example:

Laravel 5 从.env位于项目根目录的文件中获取与环境相关的变量。您只需要设置APP_ENV为您想要的任何内容,例如:

APP_ENV=development

This is used to identify the current enviroment. If you want to display errors, you'll need to enable debug mode in the same file:

这用于识别当前环境。如果要显示错误,则需要在同一文件中启用调试模式:

APP_DEBUG=true

The role of the .envfile is to allow you to have different settings depending on which machine you are running your application. So on your production server, the .envfile settings would be different from your local development enviroment.

.env文件的作用是允许您根据运行应用程序的机器进行不同的设置。因此,在您的生产服务器上,.env文件设置将与您的本地开发环境不同。

回答by Nino Paolo

Laravel 5 uses .envfile to configure your app. .envshould not be committed on your repository, like github or bitbucket. On your local environment your .envwill look like the following:

Laravel 5 使用.env文件来配置您的应用程序。.env不应在您的存储库中提交,例如 github 或 bitbucket。在您的本地环境中,您.env将如下所示:

# .env
APP_ENV=local

For your production server, you might have the following config:

对于您的生产服务器,您可能具有以下配置:

# .env
APP_ENV=production

回答by Sergio Paiva

Do not forget to run the command php artisan config:clearafter you have made the changes to the .env file. Done this again php artisan env, which will return the correct version.

不要忘记在php artisan config:clear对 .env 文件进行更改后运行该命令。再次执行此操作php artisan env,将返回正确的版本。

回答by Sjeiti

What you could also have a look at is the exposed method Application->loadEnvironmentFrom($file)

你还可以看看暴露的方法 Application->loadEnvironmentFrom($file)

I needed one application to run on multiple subdomains. So in bootstrap/app.phpI added something like:

我需要一个应用程序在多个子域上运行。所以在bootstrap/app.php我添加了类似的东西:

$envFile = '.env';
// change $envFile conditionally here
$app->loadEnvironmentFrom($envFile);

回答by Marcin ?ojewski

In Laravel the default environment is always production.

在 Laravel 中,默认环境始终是生产环境。

What you need to do is to specify correct hostname in bootstrap/start.phpfor your enviroments eg.:

您需要做的是bootstrap/start.php为您的环境指定正确的主机名,例如:

/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.
|
*/

$env = $app->detectEnvironment(array(
    'local' => array('homestead'),
    'profile_1' => array('hostname_for_profile_1')
));