Artisan unable to use $_SERVER variables from database config file
我目前正在共享主机帐户上部署Laravel项目。这是一个开放项目,并作为公共资源库托管在GitHub上。结果,我在生产环境中使用由
database.php文件的内容类似于
1 2 3 | $database = $_SERVER['DBNAME']; $database_user = $_SERVER['DBUSER']; |
这就像部署到PagodaBox时所做的一样,并且对于所有应用程序都可以在浏览器中正常运行的应用程序而言,它运行正常,没有任何抱怨。
我遇到的问题是,工匠无法使用这些变量,而是在处理
有没有一种方法可以使技术人员"查看"这些环境变量?
到目前为止证明对我有用的答案:
http://forums.laravel.io/viewtopic.php?pid=8455
和
Laravel中环境驱动的数据库设置?
因为Artisan是CLI PHP请求-该请求永远不会命中
解决方法-您可以在artisan文件本身的第3行中定义变量(在
1 2 | $_SERVER['DBNAME'] = 'test'; $_SERVER['DBUSER'] = 'something'; |
编辑:我刚刚注意到您说这是公共托管在github上的-所以您不想在文件中包含用户名/密码吗? 也许将artisan文件作为
Laravel内置了设置环境变量的功能,因此没有理由在
有关要保护的环境变量,请参阅文档的此部分。
http://laravel.com/docs/configuration#protecting-sensitive-configuration
报价单:
... create a
.env.local.php file within the root of your project [...] The .env.local.php should return an array of key-value pairs, much like a typical Laravel configuration file:
1
2
3
4All of the key-value pairs returned by this file will automatically be available via the $_ENV and $_SERVER PHP"superglobals". You may now reference these globals from within your configuration files:
1 'key' => $_ENV['TEST_STRIPE_KEY']Be sure to add the
.env.local.php file to your.gitignore file. This will allow other developers on your team to create their own local environment configuration, as well as hide your sensitive configuration items from source control.Add your private environment variables
1
2
3
4