您可以从当前环境中检索variables的FPMconfiguration统计信息。 然而,在使用Nginx和PHP-FPM的ubuntu上,我找不到从环境中检索variables值的方法, 而无需在php-fpm.conf或nginx fcgi params中对它进行硬编码 。
有没有办法从/ etc / environment或/etc/bash.bashrc获取环境variables?
例如:
clear_env = no ENV[SECRET_TOKEN] = $SECRET_TOKEN
我认为主要的问题是无法修改www-data的环境variables。 as >sudo -H -u www-data bash -c "env"不包括SECRET_TOKEN 。
看起来像唯一的方法是手动添加环境variables 。
我修改了一下代码
#!/usr/bin/php <?php $confFile = '/etc/nginx/fastcgi_params'; // Update the fpm configuration to make the environment variables available // NOTE: ONLY in the CLI will $_SERVER have environment variables in it. $content = file_get_contents($confFile); $line = false; foreach ($_SERVER as $name => $val) { if (strstr($name, 'SYMFONY') !== false) { $line = "fastcgi_param {$name} {$val};\n"; # Either Add or Reset the variable if (strstr($content, $name) !== false) { $content = preg_replace('/fastcgi_param[\s\t]+'.$name.'\][\s\t]+.*?\n/', $line, $content); echo "MODIFIED {$name}\n"; } else { $content .= "\n{$line}"; echo "ADDED {$name}\n"; } } } if ($line) { file_put_contents($confFile, $content); }