0

We have autoscaling set up for our symfony3 application. We are using aws codedeploy to deploy to autoscaling instances.

My appspec.yml file

version: 0.0
os: linux
files:
  - source: /
    destination: /usr/share/nginx/<some_dir>
hooks:
  AfterInstall:
    - location: post_deploy.sh
      timeout: 180
      runas: ubuntu

post_deploy.sh

#!/bin/bash
doc_root=/usr/share/nginx/<some_dir>
current_dir=$PWD
cd $doc_root
sudo -E composer install --no-interaction --no-dev --optimize-autoloader
cd $current_dir

and also exported environment variables for parameters.yml file

when we deploy revision, codedeploy succeed in deployment. But when i access my app through browser, nginx error log says:

PHP Fatal error:  Uncaught exception 'Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException' with message 'You have requested a non-existent parameter "database.host". Did you mean one of these: "database_host", "database_port"?

Strange thing is that when i run post_deploy.sh script manually by logging in to my server it executes well and no error afterwards. I don't know how to deal with it.

Prem Sompura
  • 631
  • 3
  • 9
  • 16

2 Answers2

0

Try to change database.host to database_host. that what's indicated in the message.

Soufiene
  • 2,218
  • 3
  • 14
  • 15
  • thats because sudo doesn't preserve env var, thats why `-E` if you run `sudo -E composer install --no-interaction --no-dev --optimize-autoloader` it will succeed and if you run this command without `-E` option it will throw mentioned exceptionerror – Prem Sompura Jul 18 '16 at 11:04
0

codedeploy doesn't preserve env var in spite of -E option. So i pass the env var in command itself, like this

sudo SYMFONY_ENV=$SYMFONY_ENV SYMFONY__DATABASE__NAME=$SYMFONY__DATABASE__NAME SYMFONY__DATABASE__USER=$SYMFONY__DATABASE__USER SYMFONY__DATABASE__HOST=$SYMFONY__DATABASE__HOST SYMFONY__DATABASE__PORT=$SYMFONY__DATABASE__PORT SYMFONY__DATABASE__PASSWORD=$SYMFONY__DATABASE__PASSWORD COMPOSER_HOME=$COMPOSER_HOME composer install --no-interaction --no-dev --optimize-autoloader

worked for me.

Prem Sompura
  • 631
  • 3
  • 9
  • 16