Laravel5.4 不同环境下 env 文件设置
来源:互联网 发布:淘宝上的货源怎么找 编辑:程序博客网 时间:2024/06/05 16:20
转自
https://laravel-china.org/articles/4934/laravel54-env-file-settings-in-different-environments
Laravel5.4现在支持不同环境下env
文件设置(好像是L5.4最新支持的吧,记不清楚了,也有可能L5.2-5.3就已经支持了),可以针对不同环境(development, staging, production)设置env文件为:
development: .env.developmentstaging: .env.stagingproduction: .env.production
根据不同环境服务器设置系统变量(可根据phpinfo()
查看APP_ENV
环境变量是否OK):
development: APP_ENV=developmentstaging: APP_ENV=stagingproduction: APP_ENV=production
这样,项目根目录下就会有根据不同环境对应的.env.xxx
文件,放入版本控制,本地的环境对应.env
不需要放入版本控制。
原理可看laravel的源码:
namespace Illuminate\Foundation\Bootstrap;use Dotenv\Dotenv;use Dotenv\Exception\InvalidPathException;use Symfony\Component\Console\Input\ArgvInput;use Illuminate\Contracts\Foundation\Application;class LoadEnvironmentVariables{ /** * Bootstrap the given application. * * @param \Illuminate\Contracts\Foundation\Application $app * @return void */ public function bootstrap(Application $app) { if ($app->configurationIsCached()) { return; } $this->checkForSpecificEnvironmentFile($app); try { (new Dotenv($app->environmentPath(), $app->environmentFile()))->load(); } catch (InvalidPathException $e) { // } } /** * Detect if a custom environment file matching the APP_ENV exists. * * @param \Illuminate\Contracts\Foundation\Application $app * @return void */ protected function checkForSpecificEnvironmentFile($app) { if (php_sapi_name() == 'cli' && with($input = new ArgvInput)->hasParameterOption('--env')) { $this->setEnvironmentFilePath( $app, $app->environmentFile().'.'.$input->getParameterOption('--env') ); } if (! env('APP_ENV')) { return; } $this->setEnvironmentFilePath( $app, $app->environmentFile().'.'.env('APP_ENV') ); }
阅读全文
0 0
- Laravel5.4 不同环境下 env 文件设置
- Laravel5.4 不同环境下 env 文件设置
- ubuntu LAMP 下laravel5.0 运行环境设置
- laravel5.5 路由分割成不同文件
- xampp 配置laravel5.4环境
- laravel5.4 服务提供者设置
- 磕磕绊绊配置linux 下 laravel5.1 环境
- windows下laravel5.5环境安装配置
- orcad 快捷键设置 (修改env文件)
- Laravel5.4 下nginx配置
- CentOs7.3下搭建LAMP环境(Apache2.4 + Mysql5.7 + PHP5.6 + Laravel5.2)
- VNC在不同桌面环境下的设置
- Wampserver+Composer搭建Laravel5.4环境
- laravel5.4+vue+element+vux环境搭建
- lamp+laravel5.4搭建项目环境
- linux下的环境文件设置说明
- windows系统下如何设置laravel5的任务
- c/vc++ 环境下不同的文件长度获取方法
- 操作系统基础之进程管理
- 8 种 NoSQL 数据库系统对比
- 关于Java集合类总结
- 前端基础进阶变量对象详解精华篇
- NoSQL系列:选择合适的数据库
- Laravel5.4 不同环境下 env 文件设置
- http://blog.nimbledroid.com/2016/05/23/memory-leaks-zh.html
- 关系代数验算 除法
- Java开发中的23种设计模式详解
- java中关于方法的解释
- [LeetCode] Longest Consecutive Sequence
- Java实现-判断字符串是否没有重复字符
- 如何搭建ThinkPHP学习开发环境
- 第十八周:( 期末机试模拟) 小黄车(c++)