papertank / envoy-deploy

Laravel Envoy Deployment
MIT License
424 stars 85 forks source link

Config:clear required for reading ENV variables #20

Closed stefkes closed 3 years ago

stefkes commented 3 years ago

After each deploy using this script, my app doesn't seem to properly read environment variables.

While my app can read from the database no problem (using env variables), it's unable to read an API key I have stored in the same .env file. When I print out env variables in a class (also DB ones), they always return NULL.

I was only able to fix the problem by adding php {{ $release }}/artisan config:clear --quiet in the deployment_finish task, just before the echo "Deployment ({{ $date }}) finished". Adding the same command in the deployment_cache didn't do the trick, I guess the config needs to cleared after the ln -nfs command?

Won't investigate more for now but you might want to look in to it.

Thanks

davidrushton commented 3 years ago

@stefkes It is best practice to use env within your config files, and this is required if you use config:cache (which this deployment script does by default for performance). See https://laravel.com/docs/8.x/configuration#configuration-caching:

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.

On your own Envoy.blade.php file you are welcome to remove the php artisan config:cache line so that the .env file is loaded on each request and config is not cached.