I'm having trouble working with environment variables in Docker.
For some reason Laravel can't see the environment variables I set within Dockerfile. Like APP_KEY, APP_ENV, etc. But when I SSH into the docker container:
docker exec -it [container_name] bash
and run the following:
php artisan tinker
> print_r($_ENV)
The environment variable exists and is set to the proper value. However, when I tried to do the same within the Blade template, I don't see the APP_KEY, APP_ENV variables at all. I've edited the php.ini
file in the Docker container so that it shows
variables_order = 'EGPCS'
Is .env
file the only way I can pass environment variables into Laravel?
I appreciate all your help.
Cheers
I solved it! Actually a friend of mine gave me the clue.
Turns out it is the FPM configuration that is removing the environment variables set by Elastic Beanstalk.
Based on this document: http://php.net/manual/en/install.fpm.configuration.php
clear_env boolean
Clear environment in FPM workers. Prevents arbitrary environmentvariables from reaching FPM worker processes by clearing the environment in workers before env vars specified in this pool configuration are added. Since PHP 5.4.27, 5.5.11, and 5.6.0. Default value: Yes.
So in your php-fpm.conf
file look for that variable and set it as follows:
clear_env = no
And you're are good to go! Your Laravel application can then pull the environment variables set in Elastic Beanstalk by using env()
I hope that helps someone. Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With