3

FPM configration stats that you can retrieve variables from your current environment. However, on ubuntu using Nginx and PHP-FPM, I can not find a way to retrieve the variable value from the environment without hard coding it in the php-fpm.conf or nginx fcgi params.

Is there a way to get the environment variable from /etc/environment or /etc/bash.bashrc?

For ex:

clear_env = no ENV[SECRET_TOKEN] = $SECRET_TOKEN 

I think the main problem is not being able to modify the env vars for www-data. As >sudo -H -u www-data bash -c "env" does not include SECRET_TOKEN.

1 Answer 1

0

Looks like the only way is to add the env vars manually.

I modified the code a bit

#!/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); } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.