lundi 20 avril 2015

doctrine credentials passed via Symfony2+nginx ENV vars aren't recognized; DB 'connection refused'. cmd line is ok. why?

Vote count: 0

In a new symfony2 install, I launch Nginx via systemd with

cat /etc/systemd/system/nginx.service 
    [Unit]
    Description=nginx
    After=syslog.target network.target

    [Service]
    Type=forking
    EnvironmentFile=-/etc/sysconfig/nginx
    ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
    ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true

where ENV vars are defined

cat /etc/sysconfig/nginx
    SYMFONY__DATABASE__USER="root"
    SYMFONY__DATABASE__PASSWORD="testtesttest"

used

cat /etc/nginx/nginx.conf
    ...
    env SYMFONY__DATABASE__USER;
    env SYMFONY__DATABASE__PASSWORD;
    ...
    http {
        ...

and verified after restart

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

According to

"How to Set external Parameters in the Service Container"
http://ift.tt/1iSzHoD

    "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."

So, changing credentials in

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_password:   ~
        locale:            en
        secret:            zzzz

with the default doctrine config

cat ./app/config/config.yml
    ...
    # Doctrine Configuration
    doctrine:
        dbal:
            driver:   "%database_driver%"
            host:     "%database_host%"
            port:     "%database_port%"
            dbname:   "%database_name%"
            user:     "%database_user%"
            password: "%database_password%"
    ...

should inherit the ENV-defined values

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

but, from site root, @ DB create with doctrine, connection is refused

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

From shell, there's no problem

mysqladmin -u root -p create test_01
Enter password: 

-< "testtesttest"

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

What needs to changed in the config above so that the doctrine execs correctly use the ENV-provided credentials?

asked 22 secs ago



doctrine credentials passed via Symfony2+nginx ENV vars aren't recognized; DB 'connection refused'. cmd line is ok. why?

Aucun commentaire:

Enregistrer un commentaire