5

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?

miken32
  • 42,008
  • 16
  • 111
  • 154
user391986
  • 29,536
  • 39
  • 126
  • 205

1 Answers1

1

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.

JasonJensenDev
  • 2,377
  • 21
  • 30
  • 2
    One of my steps when I deploy my system on the server is to run php artisan migrate in production. That's a problem because my config/database.php is using env('DB_HOST') in this format and that's NULL when ran through the command line in production. I did set these in my system environment so they work when ran through the php web server but that doesn't solve my problem.. – user391986 Jun 19 '15 at 04:40
  • 1
    I might not be fully understanding what you're getting at then. You should have a different .env file for each server that you deploy to. The reason for this is that you might have different environment settings on your dev server than on your production server.If it works fine when copy the .env file to your production server, then just keep it that way because there is nothing wrong with that. – JasonJensenDev Jun 19 '15 at 05:06
  • haha... I think we're going around in circles :-) The .env ISN'T part of the repo. The .env file should be created after the repo has been setup on the server and since the .gitignore file ignores the .env file, it won't be affect your repo at all. – JasonJensenDev Jun 19 '15 at 14:46