Closed stefkes closed 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 theenv
function from within your configuration files. Once the configuration has been cached, the.env
file will not be loaded; therefore, theenv
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.
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 thedeployment_finish
task, just before theecho "Deployment ({{ $date }}) finished"
. Adding the same command in thedeployment_cache
didn't do the trick, I guess the config needs to cleared after theln -nfs
command?Won't investigate more for now but you might want to look in to it.
Thanks