2

I have 3 environments

  • development
  • staging
  • production

When I use amazon beanstalk every request goes through a load balancer from which point you end up on an ec2 server which could be different every time (hence the problem of figuring out the environment, I can't use the machine name as it's different every time).

I found out about environment variables in beanstalk configuration so I pass an environment variable PARAM_1 from .ebextensions.myapp.config that essentially dictates the environment to use with the following trick.

$env = $app->detectEnvironment(array(
  'staging' => $_SERVER['PARAM_1'] == 'staging' ? array(gethostname()) : array('not-staging'),
  'production' => $_SERVER['PARAM_1'] == 'production' ? array(gethostname()) : array('not-production'),
  'development' => array('mylocalname')
));

This works fine except for php artisan commands! For some reason when running the artisan commands I can not access this environment variable so I'm stuck! I would like to run php artisan migrate but how do I tell it the environment it's in! (based on the environment I have different database configs)

user391986
  • 29,536
  • 39
  • 126
  • 205

1 Answers1

3

You can define the environment like this:

php artisan migrate  --env=Development

You can also use another SO answer to hard code the artisan enviornment into your code: Environment driven database settings in Laravel?

Community
  • 1
  • 1
Laurence
  • 58,936
  • 21
  • 171
  • 212