Environment variable not recognized when deployed on an elastic beanstalk

I am trying to deploy a Laravel application in Elastic Beanstalk in development mode. To make the application run in development mode, and not in production, I did the following in my file /bootstrap/start.php:

$env = $app->detectEnvironment(function() {
    return $_ENV['ENV_NAME'];
});

To create an environment variable, I created a file .configin the following path: /.ebextensions/00environmentVariables.configwith this content:

option_settings:
   - namespace: aws:elasticbeanstalk:application:environment
     option_name: ENV_NAME
     value: development
   - option_name: DB_HOST
     value: [redacted]
   - option_name: DB_PORT
     value: [redacted]
   - option_name: DB_NAME
     value: [redacted]
   - option_name: DB_USER
     value: [redacted]
   - option_name: DB_PASS
     value: [redacted]

When I run eb startfrom the command line, it spins an instance of EC2 and tries to provide it, after which it informs me of an error. and check the logs. In the logs I can see these entries:

PHP note: Undefined index: ENV_NAME in /var/app/ondeck/bootstrap/start.php on line 28

Note: Undefined index: ENV_NAME in /var/app/ondeck/bootstrap/start.php on line 28

- ENV_NAME , 00environmentVariables.config. , , , EB:

enter image description here

:

  • , .config
  • - Laravel - , ENV_NAME eixsts
  • ENV_NAME eixsts .config, Elastic Beanstalk

, , HTTP- Apache, PHP CLI.

, ENV_NAME /usr/bin/composer.phar install.

, - CLI PHP, Apache.

, SSH'd EC2, Laravel Elastic Beanstalk, , `` printenv`:

ENV_NAME=development

, die(var_dump($_SERVER)); PHP CLI, , . $_ENV getenv().

PHP CLI, , Apache PHP-?

test.php : die(var_dump($_ENV));.

php test.php, , , CLI PHP.

+4
2

YAML script, root , ec2. .ebextensions .config.

PHP cli,

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/job_after_deploy.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      source /opt/elasticbeanstalk/support/envvars
      # Run PHP s here. #

XuDing

0

, .env 5 .

.ebextensions

   "/opt/elasticbeanstalk/hooks/appdeploy/post/91_set_create_app_env_file_job.sh":
  mode: "000755"
  owner: root
  group: root
  content: |
    #!/usr/bin/env bash

    echo "Removing any existing CRON jobs..."
    crontab -r

    APP_ENV=/var/app/current/.env
    EB_ENVVARS=/opt/elasticbeanstalk/support/envvars
    CONSTANTS=/var/app/current/.constants
    CRON_CMD="grep -oE '[^ ]+$' $EB_ENVVARS > $APP_ENV; cat $CONSTANTS >> $APP_ENV"

    echo "Creating .env file...."
    eval $CRON_CMD

    echo "Scheduling .env file updater job to run every 5 minutes..."
    (crontab -l 2>/dev/null; echo "*/5 * * * * $CRON_CMD")| crontab -

, , , AWS.

, .

0

All Articles