dtyqflrr775518 2013-01-19 07:51 采纳率: 100%
浏览 87
已采纳

Artisan无法使用数据库配置文件中的$ _SERVER变量

I am currently deploying a Laravel project on my shared hosting account. It is an open project and hosted on GitHub as a public repository. As a result I'm using dynamic variables set by an .htaccess file in my database.php configuration file for my production environment. This allows me to also update my deployment using a git pull command on my host which helps speed up work.

The database.php file has something similar to

$database = $_SERVER['DBNAME'];

$database_user = $_SERVER['DBUSER'];

This is much like what is done when deploying to PagodaBox & works perfectly fine for the application with all things functioning as expected in the browser, no complaints.

The problem I have is that artisan is unable to use these variables and will attempt instead to connect to the database using what I believe to empty variables when processing a migrate instruction. I get an error that artisan tried to connect to the databases with no password. I have been calling artisan using --env=production and have tested this but found that it will only work if the database.php file has the variables specified explicitly instead of as environment variables.

Is there a way of causing artisan to "see" these environment variables?


answers that have proved useful to me so far:

http://forums.laravel.io/viewtopic.php?pid=8455

and

Environment driven database settings in Laravel?

  • 写回答

2条回答 默认 最新

  • donjd86266 2013-01-19 08:49
    关注

    Because Artisan is a CLI PHP request - the request never hits the .htaccess file - and therefore your variables are never set.

    As a workaround - you could define the variables inside the artisan file itself on line 3 (just after the <?php)

    $_SERVER['DBNAME'] = 'test';
    $_SERVER['DBUSER'] = 'something';
    

    edit: I just noticed you said this is public hosted on github - so you wont want to include your username/password in the file? Maybe put the artisan file as part of the .gitignore group - so you dont push/pull that single file?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型