Laravel中的环境问题 [英] Environment issue in Laravel

查看:68
本文介绍了Laravel中的环境问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$env = $app->detectEnvironment(array(
    'local' => array('*localhost*'),
    'test'  => array('chan.app'),
));

这是我在boostrap/start.php中设置的方法,也是我在主机文件中设置ip的方法

This is how I set in boostrap/start.php, and I set ip in hosts file


127.0.0.1 localhost
127.0.0.1 chan.app

无论我键入http://localhost/还是http://chan.appApp::environment()总是显示production,因此我无法为其更改数据库配置.

No matter I type http://localhost/ or http://chan.app, App::environment() always reveal production, therefore I can't change database config for it.

推荐答案

由于安全问题,禁止在环境中使用 url域. Laravel表示改用主机名.

Because of security issues, the use of url domains in environment is forbidden. Laravel says to use hostnames instead.

这就是为什么我怀疑Laravel是否可以正确识别(检测)您的配置的原因,因为两者都在同一台计算机上.

This is why I doubt, that Laravel would recognise (detect) your configuration correctly, as both are on the same machine.

摘录自 4.2升级指南:

环境检测更新

出于安全原因,URL域可能不再用于检测您的 应用环境.这些值很容易被欺骗并允许 攻击者修改请求的环境.你应该转换 您的环境检测以使用计算机主机名(hostname命令 在Mac,Linux和Windows上).

For security reasons, URL domains may no longer be used to detect your application environment. These values are easily spoofable and allow attackers to modify the environment for a request. You should convert your environment detection to use machine host names (hostname command on Mac, Linux, and Windows).

编辑

比方说,您想要一个本地的,实时的环境.

1.为每种配置创建文件夹:

  • 创建文件夹local& /app/config/内的live
  • 在每个这些文件夹中,您创建要从/app/config/覆盖的配置文件,
  • Create a folder local & live inside /app/config/
  • Inside each of those folders you create the config file(s) you wish to override from /app/config/,

例如,在您的live(生产)环境中,您不想激活debug选项.

For example, in your live (production) environment, you don't want to have the debug option activated.

  • /app/config/live文件夹中创建文件app.php.
  • 在内部,您将只返回所需的选项来覆盖,如原始/app/config/app.php中所定义.

  • Create a file app.php in the /app/config/live folder.
  • Inside, you'll just return the desired options to override, as defined in the original /app/config/app.php.

return array('debug' => false);

在本地环境中,将"debug"设置为true,以进行开发.

In the local environment, 'debug' would be set to true, for development.

2.将环境添加到框架:

在您的/bootstrap/start.php文件中:

$env = $app->detectEnvironment(array(
    'local' => array('local-machine-name'),
    'live' => array('yourdoamin.com')
));

那是重要的部分:

-开发(本地):->机器名称

-生产:->根URL(yourdomain.com),代表计算机"名称

有关更多信息,请参见有关环境配置的文档.

See the docs about environment config for further information.

这篇关于Laravel中的环境问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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