Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony2+nginx external ENV vars aren't recognized by doctrine DB actions. fails with 'connection refused'. #14426

Closed
ghost opened this issue Apr 21, 2015 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 21, 2015

I'm running Symfony2 2.6.6, nginx 1.7.12 on linux/64.

env VARS

SYMFONY__DATABASE__PASSWORD => "testtesttest"
SYMFONY__DATABASE__USER => "root"

have been set in shell & nginx.

As documented

"How to Set external Parameters in the Service Container":
 http://symfony.com/doc/current/cookbook/configuration/external_parameters.html

    "Now that you have declared an environment variable, it will be present in the PHP $_SERVER global variable. Symfony then automatically sets all $_SERVER variables prefixed with SYMFONY__ as parameters in the service container.

    You can now reference these parameters wherever you need them."

Verifying,

php -i | grep SYMFONY__DATABASE
    SYMFONY__DATABASE__PASSWORD => "testtesttest"
    SYMFONY__DATABASE__USER => "root"
    _SERVER["SYMFONY__DATABASE__PASSWORD"] => "testtesttest"
    _SERVER["SYMFONY__DATABASE__USER"] => "root"

setting symfony parameters

cat ./app/config/parameters.yml
    parameters:
        database_driver:   pdo_mysql
        database_host:     127.0.0.1
        database_port:     3306
        database_name:     test_01
        database_user:     "%database.user%"
        database_password: "%database.password%"
        mailer_transport:  smtp
        mailer_host:       ~
        mailer_user:       "%mailer.user%"
        mailer_password:   "%mailer.password%"
        locale:            en
        secret:            xxxx

symfony "at shell" should inherit the ENV-defined values

user <= "%database_user%" <= "%database.user%" <= SYMFONY__DATABASE__USER <= "root"
password <= "%database_password%" <= "%database.password%" <= SYMFONY__DATABASE__PASSWORD <= "testtesttest"

from site root, DB create with doctrine fails with "connection refused"

php app/console doctrine:database:create
    Could not create database for connection named `test_01`
    SQLSTATE[HY000] [2002] Connection refused

From shell, with mysql tools, there's no problem

mysqladmin -u root -p create test_01
    Enter password: 
    => "testtesttest"

mysqladmin -u root -p 
    ...
    +------------------------------+
    |          Databases           |
    +------------------------------+
    ...
    | test_01                      |
    +------------------------------+

Also, editing

./app/config/parameters.yml
    ...
-       database_user:     "%database.user%"
-       database_password: "%database.password%"
+       database_user:     root
+       database_password: "testtesttest"
    ...

All doctrine cmds, e.g.,

php app/console doctrine:database:drop --force
php app/console doctrine:database:create
php app/console doctrine:schema:create

now work without error

@ghost
Copy link

ghost commented Apr 21, 2015

it's probably because of this: #7555

@jakzal
Copy link
Contributor

jakzal commented Apr 21, 2015

Indeed. Closing as a duplicate.

@jakzal jakzal closed this as completed Apr 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant