-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k

Description
Bug report?
no. well, maybe docs/best-practices?
Feature request?
no
BC Break report?
no
RFC?
no
Symfony version
3.3.2
Reading
How to Set external Parameters in the Service Container
http://symfony.com/doc/current/configuration/external_parameters.html
usage of SYMFONY__ vars has been deprecated,
New in version 3.3: The support of the special SYMFONY__ environment variables was deprecated in Symfony 3.3 and it will be removed in 4.0. Instead of using those variables, define regular environment variables and get their values using the %env(...)% syntax in your config files.
In my SF 3.3 proj, I config to use env vars for DB credentials,
cat app/config/paramaters.yml
parameters:
database_host: '%env(SF_DB_HOST)%'
database_port: '%env(SF_DB_PORT)%'
database_name: '%env(SF_DB_NAME)%'
database_user: '%env(SF_DB_USER)%'
database_PASS: '%env(SF_DB_PASS)%'
database_path: null
database_memory: null
env(SF_DB_HOST): localhost
env(SF_DB_PORT): 3306
env(SF_DB_NAME): noop_name
env(SF_DB_USER): noop_user
env(SF_DB_PASS): noop_PASS
...
In nginx config, I define server vars using php-fpm's fastcgi_param,
cat sites-enabled/vhost01.conf
...
location ~ ^/app\.php(/|$) {
fastcgi_param SF_DB_HOST "localhost"
fastcgi_param SF_DB_PORT "3306"
fastcgi_param SF_DB_NAME "secure_name"
fastcgi_param SF_DB_USER "secure_user"
fastcgi_param SF_DB_PASS "secure_pass";
...
in php.ini, I've ensured
php -i | egrep -i "variables_order|request_order"
request_order => EGP => EGP
variables_order => EGPCS => EGPCS
and in my php-fpm pool conf
...
[www]
clear_env = no
env[SF_DB_PASS] = $_SERVER['SF_DB_PASS']
env[SF_DB_USER] = $_SERVER['SF_DB_USER']
env[SF_DB_NAME] = $_SERVER['SF_DB_NAME']
env[SF_DB_PORT] = $_SERVER['SF_DB_PORT']
env[SF_DB_HOST] = $_SERVER['SF_DB_HOST']
...
but on webserver + php-fpm restart,
phpinfo()
...
PHP Variables
...
$_SERVER['SF_DB_HOST'] localhost
$_SERVER['SF_DB_PORT'] 3306
$_SERVER['SF_DB_NAME'] secure_name
$_SERVER['SF_DB_USER'] secure_user
$_SERVER['SF_DB_PASS'] secure_pass
...
are set as expected, but the ENV vars -- needed by SF -- are not
phpinfo()
...
Environment
...
SF_DB_HOST no value
SF_DB_PORT no value
SF_DB_NAME no value
SF_DB_USER no value
SF_DB_PASS no value
...
php7's php.ini contains comment that ENV var use is not recommended
; This directive determines which super global arrays are registered when PHP
; starts up. G,P,C,E & S are abbreviations for the following respective super
; globals: GET, POST, COOKIE, ENV and SERVER. There is a performance penalty
; paid for the registration of these arrays and because ENV is not as commonly
; used as the others, ENV is not recommended on productions servers.
this thread
https://stackoverflow.com/questions/8551592/setting-env-fka-http-env-vars-with-nginx-php-fpm
suggests that ENV setting in php-fpm is not reliable (?).
These issues
SYMFONY__ Env Variables overwriten by parameters.yml #7555
https://github.com/symfony/symfony/issues/7555
Symfony2+nginx external ENV vars aren't recognized by doctrine DB actions. fails with 'connection refused'.
https://github.com/symfony/symfony/issues/14426
appear to still refer to / depend on SYMFONY__ env vars, which are, as above, deprecated.
So the question is how, going forward, to access _SERVER[...] vars in parameters/yml so, for example, doctrine:... cmds can use them?