Laravel 4.1部署 - 生产.env.php未被识别 [英] Laravel 4.1 Deployment - Production .env.php not being recognised
问题描述
由于某种原因,我的生产Laravel应用程序认为它在当地的环境。
/var/www/appname/.env.php
<?php
return
[
' APP_ENV'=> 'production',
'DB_HOST'=> 'HIDDEN',
'DB_NAME'=> 'HIDDEN',
'DB_PASSWORD'=> 'HIDDEN'
];
/var/www/appname/bootstrap/start.php
$ env = $ app-> detectEnvironment(function()
{
return getenv('APP_ENV' )?:'local';
});
/var/www/appname/app/config/database.php
...
...
'mysql'=>数组(
'driver'=>'mysql',
'host'=> getenv('DB_HOST'),
'database'=> getenv('DB_NAME'
'username'=> getenv('DB_USERNAME'),
'password'=> getenv('DB_PASSWORD'),
'charset'=>'utf8',
'collation'=>'utf8_unicode_ci',
'前缀'=>'lar_',
),
...
...
sudo php artisan env
(通过SSH)
`当前应用程序环境:local
php artisan tinker
then getenv('DB_NAME')
$ php artisan tinker
[1]> GETENV( DB_NAME);
// false
所以我的环境变量都没有设置,或者Laravel不是识别生产环境的 .env.php
文件。
更新 p>
在IRC上的Anultro帮助下,似乎还没有加载.env.php。因此,在Laravel尝试检测环境之前,必须设置APP_ENV。这是有道理的,因为Laravel在确定是否使用 .env.php
或 .env.local.php
。
说完这个,还应该使用 .env.php
来存储数据库凭据和密钥等...但是我仍然有一个问题,因为当我尝试运行 getenv('DB_NAME')
$ b
任何建议?
对于所有想知道...解决这个问题的人问题,我刚刚在生产服务器上编辑我的httpd.conf文件,如下所示:
SetEnv APP_ENV production
现在laravel知道应用程序正在生产中。
如果你正在使用nginx,我现在已经迁移了我的网站,添加以下代码,将脚本传递到活动站点中的FCGI服务器 - 可用 / etc / nginx / sites-available / {sitename}
:
fastcgi_param APP_ENV production;
For some reason, my production laravel app thinks that it is in the local environment.
/var/www/appname/.env.php
<?php
return
[
'APP_ENV' => 'production',
'DB_HOST' => 'HIDDEN',
'DB_NAME' => 'HIDDEN',
'DB_PASSWORD' => 'HIDDEN'
];
/var/www/appname/bootstrap/start.php
$env = $app->detectEnvironment(function()
{
return getenv('APP_ENV') ?: 'local';
});
/var/www/appname/app/config/database.php
...
...
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'lar_',
),
...
...
sudo php artisan env
(via SSH)
`Current application environment: local
php artisan tinker
then getenv('DB_NAME')
$ php artisan tinker
[1] > getenv('DB_NAME');
// false
So either my environment variables are not being set, or Laravel is not recognising my .env.php
file for the production environment.
Update
With some help from Anultro on IRC, it appears that .env.php is not loaded yet. As such APP_ENV must be set before laravel tries to detect environments. This makes sense, because Laravel needs to know what environment is running before determining whether to use .env.php
or .env.local.php
.
Having said this, .env.php
should still be used to store db credentials and secret keys etc... But I am still having a problem because the app is still returning false when I try to run getenv('DB_NAME')
Any suggestions?
For all who want to know... to solve this issue, I just edited my httpd.conf file on the production server as follows:
SetEnv APP_ENV production
Now laravel knows that the app is in production.
If you are using nginx which I have now migrated my site to add the following where you pass scripts to the FCGI server in the active sites-available /etc/nginx/sites-available/{sitename}
:
fastcgi_param APP_ENV production;
这篇关于Laravel 4.1部署 - 生产.env.php未被识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!