#Env vars being ignored, can't set dev mode

47 messages · Page 1 of 1 (latest)

fathom goblet
#

Hello there. I am running Laravel inside a container. Inside the container, echo $APP_ENV gives test. echo $APP_DEBUG gives true. Yet when I run artisan migrate, I get a big banner error message telling me that the application is in production, so it doesn't want to run. (Or asks for confirmation, but since this is part of a non-interactive script I cannot say yes.). I've also tried setting APP_ENV to "local", no difference.

How else do I tell Laravel that it's not in production mode?

fathom goblet
#

Ugh. And even if I --force, I then get a "connection refused" error. Despite verifying that my DB_* env vars are correct.

lean ermine
#

Have you cached your config and then made changes to your env? It will still be using the cached config?

fathom goblet
#

I... don't think so? This all happening in a CI build in GitHub Actions. (It runs fine locally.)

lean ermine
#

It’s usually the thing that would stop env changes being reflected. But idk what your doing without further info

fathom goblet
#

Would an abbreviated GitHub Actions script be useful here?

lean ermine
#

Yeah give it a go

fathom goblet
#

Stand by while I trim...

lean ermine
#

Or put it in a gist

fathom goblet
#

Hm, let me test one idea first...

#

Left comments indicating what breaks.

lean ermine
fathom goblet
#

It's built in to the Lando configuration.

lean ermine
#

Yeah idk what Lando is or how it works but if MySQL does exist inside that container then clearly it’s using different connection info

fathom goblet
#

Lando is a layer atop docker-compose. It uses its own config file to translate down to a typical LAMP configuration (php-fpm container, nginx container, MySQL container, etc.).

#

What I don't get is why the query is trying to read from "homestead", when none of the env vars say homestead. But the .env file still has "homestead" in it, but that should be ignored in favor of the env vars.

lean ermine
fathom goblet
#

Most of them require a DB. (I didn't write them.). And we're using lando for local dev, so running tests on CI using the same configuration seems logical.

lean ermine
#

The DB requirement is a non-issue as you can easily setup mysql on actions.

#

But if sticking with lando is a req then your just gonna have to keep on debugging as i have no idea

fathom goblet
#

There's other dependencies we're also installing in the app container.

#

Why would laravel not be reading the env vars? That's the part I don't get.

#

They're set inside the app container, yet it's not using them.

lean ermine
#

Is the homestead in your .env.example which is copied to .env

fathom goblet
#

Yes.

#

Which is why I'm confused, since the env var should be taking priority over that, no?

lean ermine
#

yes maybe why not just change your .env.example to have the correct info in it

#

or create an .env.ci and us that instead

fathom goblet
#

Do all .env.* files get parsed?

lean ermine
#

no? you would still copy it to .env

fathom goblet
#

Oh, I see what you mean.

lean ermine
#

I think if you had an .env.testing and ran a command with APP_ENV=testing it would prefer .env.testing to .env as that is how that would work

fathom goblet
#

I'll try that, one moment.

#

What's the trigger for "production mode"?

lean ermine
#

?

#

its APP_ENV=production

fathom goblet
#

And if APP_ENV isn't set at all?

lean ermine
#

config/app.php has a default

fathom goblet
#

Ah ha. That's probably where that was coming from. For whatever reason it wasn't reading APP_ENV, so falling back to "production".

lean ermine
fathom goblet
#

Huh. OK, so, I don't understand what is going on, but any mechanism that results in .env having the credentials I want, works. Anything that involves setting actual env vars, gets ignored.

lean ermine
#

Yeah usually system variables get priority i guess however you are trying to set the variables isn't actually applying

fathom goblet
#

Which is bizarre, since echoing them in the container shows they are set.

lean ermine
#

maybe lando lives in opposite world

fathom goblet
#

¯_(ツ)_/¯

#

Too busy arguing with Han.