user391986
user391986

Reputation: 30886

Laravel and environment variables in command line production without .env file

When I upgraded to Laravel 5 I started using the env system where I set all my configurations inside this file at the root.

.env

DB_HOST=x.x.x.x.x
DB_USERNAME
...

This file is not part of my repo and when I deploy I set the same variables onto my system environment variables (using amazon beanstalk here) so they are accessible without the need of the .env file.

So that all works but now when I use the command line in my scripts in production these system environment variables don't seem to be accessible in the command line. They are however accessible when the PHP is served through the web server.

I found if I copy add back this .env file then it works in the command line but that's why I'm confused, I thought this system was to prevent committing sensitive information to the repo and now it seems I have to do so so that I can use my php artisan migrate and other commands in production.

Am I missing something? Is there a way to get the system environment variables available in the command line or do I have to somehow create that .env file dynamically in production?

Upvotes: 5

Views: 1850

Answers (1)

JasonJensenDev
JasonJensenDev

Reputation: 2407

I always thought that the .env file was just part of setting up your server. The .env file is ignored by git, so once it's setup, you can push/pull to your heart's content and it'll leave the .env file alone. That's at least how I've done it so far.

Upvotes: 1

Related Questions