gnguyen's avatar

env('APP_ENV') outputs incorrectly

When I output env('APP_ENV'), it returns "staging". However, my env('APP_ENV') should actually be "local", and it isn't updating properly. I ran php artisan config:cache and php artisan config:clear but it still remains "staging", and I didn't change the value anywhere else. Is there a reason for this?

0 likes
12 replies
gnguyen's avatar

Got it. However, it still returns "staging" instead of "local".

It seems I have done this:

If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded; therefore, the env function will only return external, system level environment variables.

Is there a way to fix this?

MichalOravec's avatar

By using config helper and don't caching config files during development.

gnguyen's avatar

Well it is a bit late to fix that now. I meant how I can reverse it so that it reads from my .env file instead of the system level or wherever it is reading my variables from now.

gnguyen's avatar

Didn't work unfortunately. Ran it and my env still reads "staging" instead of "local"

MichalOravec's avatar

Then you changed file and cleared config cache in another project.

gnguyen's avatar

That was not the case for me. This is the only project I was working on where I used php artisan config:cache, and I have not worked on another project. I have uploaded this one to a "staging" environment, but I have not run any command line commands in that environment, and the files are almost exactly the same for both.

MichalOravec's avatar

Run again php artisan config:cache on that staging server.

And always after deployment.

gnguyen's avatar

I don't think I'm able to run command line commands on that server (I don't know enough and don't want to break anything already existing), so I created a new variable in my app.php file called environment and setting that to local, while creating it in my .env file and pointing everything to environment instead of env. Though it's not a great fix, will this be okay?

Snapey's avatar

check config/app.php. Is it even looking at APP_URL ?

Jester_'s avatar

I had a similar problem running the local env on php artisan serve ... restarting the local server helped

Please or to participate in this conversation.