11

I just changed a constant inside my .env file. The new value is shown up correctly with php-cli (via tinker), but not in my web app (php-fpm).

So far I've tried everything as suggested:

sudo service nginx restart
sudo service php7.0-fpm restart
sudo service php7.0-fpm reload

.

php artisan config:cache

This will generate a cache config file in bootstrap/cache/config.php

php artisan config:clear

This will remove cache config file in bootstrap/cache/config.php

php artisan cache:clear

What exactly does does ? What type of cache does it clear?

php artisan clear-compiled

This clear compile classes

composer dump-autoload

This will generate/update composer autoload file.

I have some .env variables that are not part of any config file. So it is useless for me to run any of the artisan commands.

None of the above php artisan commands don't deal directly with $_ENV.

Seems that $_ENV is stored somewhere in the server and laravel cannot update it once properties are populated.

The only solution I've found is restarting the server.

I'm running a Laravel Forge instance.

miken32
  • 42,008
  • 16
  • 111
  • 154
John Smith
  • 1,848
  • 3
  • 13
  • 24
  • try these two `php artisan clear-compiled` and `composer dump-autoload`. – infernaze Jun 16 '16 at 03:35
  • Take a look at this [this](http://stackoverflow.com/questions/22126709/laravel-4-1-deployment-production-env-php-not-being-recognised) question. Might be similar issue. – infernaze Jun 17 '16 at 02:27
  • 2
    I realized that it was because the queue worker has its own process running, so queue tasks won't use the updated $_ENV. Restarting the worker via supervisord, reloads $_ENV. – John Smith Dec 08 '16 at 01:16
  • @JohnSmith you save me two years later. Thanks :) – Simion Dec 05 '18 at 18:44
  • Does this answer your question? [Laravel not reading changes to .env file](https://stackoverflow.com/questions/34420761/laravel-not-reading-changes-to-env-file) – miken32 Aug 04 '23 at 17:49

2 Answers2

14

If it is cached and you need to reload it you can simply use:

php artisan config:clear

This will pull in any changes that you have since made.

James
  • 15,754
  • 12
  • 73
  • 91
2

Try to delete the config on file on: Bootstrap/cache/config.php

AS well you can try: php artisan config:cache or php artisan cache:clear