Skip to content

Environment variables from vhost not passed to service container in production #19015

@kinekt4

Description

@kinekt4

I'm using the following technique to set some environment variables (db params in particular):

As described in the document, they need to be set in two different places:

  • In Apache vhost
  • In command line (prior to running symfony commands)

When in the development environment (app_dev.php) and connecting to the DB

$db = Propel::getWriteConnection('default');

the $db object references the correct database as defined in my vhost.

However, when in production environment (app.phpp) and connecting to the DB, the $db object references the database as defined in the CLI instead.

I've been able to mitigate this issue by setting debug to true in the front controller:

// app.php
$kernel = new AppKernel('prod', true);

So, it seems like a caching issue but I'm not sure if it's a Symfony or a Propel issue.

Also, I wonder if this issue may be related: #7555

How To Reproduce

Vhost

<VirtualHost *:443>    
  ...
  # DATABASE PARAM BY VHOST
  SetEnv          SYMFONY__DATABASE__HOST 127.0.0.1
  SetEnv          SYMFONY__DATABASE__USER test-user
  SetEnv          SYMFONY__DATABASE__PASSWORD test-password
  SetEnv          SYMFONY__DATABASE__NAME test-db
  ...
</VirtualHost>

config.yml

propel:
    database:
        connections:
            default:
                adapter:                %database_adapter%
                user:                   %database_user%
                password:               %database_password%
                dsn:                    %database_driver%:host=%database_host%:%database_port%;dbname=%database_name%;
                options:
                    ATTR_PERSISTENT:    NULL
                attributes:             []

parameters.yml

parameters:
    database_adapter: mssql
    database_driver: pdo_dblib
    database_host: '%database.host%'
    database_port: 1433
    database_name: '%database.name%'
    database_user: '%database.user%'
    database_password: '%database.password%'  

Clear Cache CLI

export SYMFONY__DATABASE__HOST=127.0.0.1
export SYMFONY__DATABASE__USER=test-user
export SYMFONY__DATABASE__PASSWORD=test-password
export SYMFONY__DATABASE__NAME=test-db

php app/console cache:clear --env=prod

Environment
OS: CentOS 7
Apache: 2.4.6
PHP: 5.6
Symfony: 2.8 (standard framework edition)
ORM: Propel
Database adapter: mssql
Database driver: pdo_dblib

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions