Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MrMoto9000's avatar

Why are environment variables not updated on deployment?

I've noticed some weird behaviour that I don't understand. When I deploy my app to Amazon Web Services, and then I later make a change to environment variables, Laravel doesn't see the change.

I can go into tinker and run env('APP_DEBUG') and see the new setting, but my app will not use the new setting: It will still share debug information on a crash, even if set to false.

I've tried running php artisan config:clear, assuming it's a caching issue, but even so it doesn't work. It's only after I force AWS to restart the app that the new environment variables are used by my app (and I think only after running config:clear, but I'm not 100% sure about that).

Why does Laravel behave this way? And how can I quickly force it to use the new environment variables when they're changed?

Thanks.

0 likes
6 replies
siangboon's avatar

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 and all calls to the env function will return null.

MrMoto9000's avatar

Yes, but that's unrelated. I don't run config:cache during deployment, and even if I did, config:clear should sort that out. Secondly, I don't call any env functions from within my code. The example I gave is APP_DEBUG and I meant it in reference to logging and debug output on crashing.

Nakov's avatar

When you say this:

It will still share debug information on a crash, even if set to false.

Do you mean the error is visible on the browser, or it is just logged in the file?

And what is your APP_ENV set to? Is it production?

Another thing is to check your config/app.php if you read from the .env file for the debug key, or you might have deleted that, so it always returns true.. or if the default is set to true :)

MrMoto9000's avatar

Ok. Im going to try and explain again: Laravel BEHAVES as though the env variables have not been updated. Theres nothing wrong with the settings themselves. This is CONSISTENT.

I can ssh into the server and tinker to view the env variables and they are shown to be the NEW values. While Laravel behaves as if it has the OLD values.

Running config:clear does not solve the problem, but restarting the server DOES.

2 likes
Nakov's avatar

@johnnyw2001 maybe config:clear does not clear the config cache because it does not have enough permissions. You can clear the config cache yourself without restarting the server :)

Just remove bootstrap/cache/config.php.

MrMoto9000's avatar

Interesting. Thanks. config:clear does return a success message oddly enough, but I will explore this.

1 like

Please or to participate in this conversation.