Getenv does not work on EC2 server

I am trying to deploy my application to production, which works well in local mode.

Thing when trying:

dd(getenv('APP_ENV'));

it returns false

but when i plug in ssh and type:

php artisan env

I get

production

Any idea why it stopped working ???

To record while creating my deployment script, run 3 commands:

composer dump-autoload -o
php artisan route:cache
php artisan config:cache

I mention this because it is probably the only software config that is different.

EDIT: I believe the problematic command is:

php artisan config:cache

If if do:

php artisan config:clear

the problem is resolved.

Tx!

+4
source share
1 answer

.env , getenv , :

bootstrap/cache/config.php

:

config('app.env');

app:

app('env');

environment :

app()->environment(); // or App::environment()

Laravel dotenv, .env , putenv, , , , Laravel , , , .env , getenv.

.env , config, , .

, BASE_URL .env :

BASE_URL=http://domain.com/

, . , config/app.php :

'base_url' => env('BASE_URL')

, iit :

config('app.base_url')

Laravel Documentation.

+2

All Articles