Reload .env constants in Laravel 5.2

John Smith picture John Smith · Jun 16, 2016 · Viewed 11.9k times · Source

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.

Answer

James picture James · Jun 16, 2016

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.