Laravel 4.1 Deployment - Production .env.php not being recognised

孤街浪徒 提交于 2019-12-03 13:27:22

问题


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?


回答1:


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;


来源:https://stackoverflow.com/questions/22126709/laravel-4-1-deployment-production-env-php-not-being-recognised

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!