#Can I host Laravel without a .env file?
12 messages · Page 1 of 1 (latest)
Yes, as .env files are just replacements for environment variables proper. So if you define actual environment variables on your production server, you don’t need an .env file.
you can also just define your production values as the 2nd parameter of the env() functions in your config files
I hope you’re joking…?
not saying its the best idea, but its possible
It’s a terrible idea. You want production credentials and secrets nowhere near your source code.
except when PHP fails to load the ENV variables on rapid concurrent requests due to the nature of the request handler - https://github.com/laravel/framework/issues/8191
I fail to see why this then means you have to stick production values in your source code? 🤷♂️
Run config:cache on deployment. Laravel app then never needs to call env
Hmm, config:cache doesn't seem to work either 🤔
Background info: I'm using a hosting service that hosts Docker via Kubernetes... so I have 3 services:
- CLI (php-cli, main service, does
composer installin the Dockerfile) - NGINX (nginx, exposed port, has copy of the files)
- PHP (php-fpm, no bash available, just running PHP-FPM)
I can ssh into cli and nginx services and can confirm printenv has APP_KEY and all other related env vars that I added to the hosting environment.
So I'm not too sure why those env vars are not read for this Laravel app 🤔
It could be that the Dockerfile needs those env vars to be added in a different scope, they are added as runtime scope for all envs of the project (thus production, development, staging, any PR-envs I spin up etc.)
mmm I think I have to do these commands in post rollout task after deployments
php artisan config:cache // flush all cached env variable
php artisan config:clear // repopulate all the env variable
php artisan cache:clear // flush all the cached content