danjas's avatar

Load correct environment

Hi all, so I have three .env files:

  • .env - required
  • .env.local - developers
  • .env.prod - online

And when I go to the site localhost:8000, I get

SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge'

because its still using .env variables when in fact I want it to use .env.local.

Here is .env:

APP_ENV=false
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=America/Chicago

CACHE_DRIVER=file
QUEUE_DRIVER=sync

and my .env.local:

APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=America/Chicago

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
QUEUE_DRIVER=sync

So, as you can see, it should load the .env.local.

Even doing: php artisan migrate --env=local yields me: SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'forge' when .env.local's DB_DATABASE is test ` What am I doing wrong?

0 likes
3 replies
sutherland's avatar

Maybe your config is cached? php artisan config:clear

1 like
danjas's avatar

@sutherland Nice. I forgot about that for Lumen and its, I believe, php artisan cache:clear but no.. still same error. :\

sutherland's avatar

Oops, didn't realize it was Lumen. It might not be something included in Lumen, a quick search of the Lumen source I don't see the same function Laravel uses to load .env.*** files.

Please or to participate in this conversation.