Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sail does not read changes in .env file #658

Closed
pfried opened this issue Jan 24, 2024 · 8 comments
Closed

Sail does not read changes in .env file #658

pfried opened this issue Jan 24, 2024 · 8 comments

Comments

@pfried
Copy link

pfried commented Jan 24, 2024

Sail Version

1.27.2

Laravel Version

10.42.0

PHP Version

8.1

Operating System

Windows (WSL)

OS Version

10.0.19045 Build 19045

Description

If I start sail with sail up the .env file is read and applied (cached?).

The Problem: Subsequent changes are not beeing reflected, If I e.g. change from APP_ENV=local to APP_ENV=production that does not work.

Workaround 1: You can run sail artisan config:cache which then reads from the .env file again and the changes are reflected. This is not advised for local development

Workaround 2: Restart sail

I searched the documentation for hints of .env related issues, but found nothing besides that if you add sail services you will need to reflect the changes back to the .env file.

I originially tried finding why my Laravel Nova gate did not work, but it branches if installed locally and does not call the gate, I changed to APP_ENV=production but nothing happened. Searching for a solution I saw some of propably related questions and issues on Stackoverflow

Steps To Reproduce

Start sail by

sail up

Make changes to .env file (e.g. APP_ENV=production)

Nothing happens

@driesvints
Copy link
Member

Are all changes not reflected or just the APP_ENV? Reason I ask is because I don't feel changing APP_ENV is a realistic example. You usually just define that one time for local dev and that's it.

@pfried
Copy link
Author

pfried commented Jan 25, 2024

Okay, its propably only the APP_ENV, if I test any other value it is reflected right away.

But: Why cant I expect that form the APP_ENV? I know the variables can get overwritten by system env variables etc. but I never set it (its docker at last).

Also why does it work when running sail up and artisan config:cache? (I mean as you wrote it might be that it gets only read once or when running config:cache.)

Do you have any idea where this might be / or not be documented?

The issue I had required setting APP_ENV to another value because laravel/nova uses it to branch its login logic and it took me a while to figure out why changing APP_ENV did not work

@driesvints
Copy link
Member

I just think changing your APP_ENV isn't a realistic use case and probably something that almost never happens. I'm sorry you got caught by this but I think for such an edge case, it's not worth updating the docs.

You should also never use config:cache locally, only in production.

@pfried
Copy link
Author

pfried commented Jan 26, 2024

"I just think changing your APP_ENV isn't a realistic use case "

I would strongly argue against that, for testing you will always want to do this, especially if you want to develop a behaviour based off the value and or you need to test things depending on it.

Given there is a value in .env one will think "Okay I change the value and it will be changed". I simply feel this does not meet a developers expectations. Closing this issue is fine, maybe it will help someone in the future as it now can be found

@Sartoric
Copy link

Found this after "artisan clearing" everything multiple times and scratching my head a bit.

Just for the sake of conversation , I add my use case :

I set Password rules based on ENV (I don't want to have constraints when developing/testing) but sometimes I need to use it.

So, now I know that if I want to test it I need to down->up sail, but I would have never thought it was related to this.
Maybe adding a note in the docs could be helpful

@thomasfw
Copy link

Also got caught out by this, so it's clearly not such a small edge case.

@marvinschroeder
Copy link

Same "problem" here, after debugged the application sourcing of the .env file and were still confused why the environment did not change.
We wanted to test the exception handling for Inertia on our local machine and were surprised that changing the APP_ENV does not change the environment on the sail container.

@vcardillo
Copy link

vcardillo commented Aug 30, 2024

@driesvints I was also caught by this bug, and I would highly encourage you/the team to update the docs.

"but I think for such an edge case, it's not worth updating the docs."

I think it's worth updating the docs with this behavior. There are cases where someone may want to simulate production locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants