6

i'm using an ubuntu:18.04 container with nginx and php-fpm7.2. I set

clear_env=no

in /etc/php/7.2/fpm/pool.d/www.conf and

variables_order = "EGPCS"

in /etc/php/7.2/fpm/php.ini

I pass pass a variable $myVar from docker-compose. Running

echo $myVar

shows the correct value.

Running php -r "echo getenv('myVar');" shows me the correct value.

Placing a file index.php into /var/www/html/ (this is my www root) containing

<?php
   echo getenv('myVar');
?>

returns me an empty string.

Can someone help me?

Thank you, Martin

1
  • Which is the user running php-fpm? Is it the one you're logged in when you invoke php -r "echo getenv('myVar');" via command-line? Commented Jul 3, 2019 at 11:37

2 Answers 2

8

This is a PHP-FPM prank.

  • Setup the clear_env = no on /etc/php/7.2/fpm/pool.d/www.conf, so;

On Dockerfile start de php-fpm with init.d, not use service.
Ex:

CMD /etc/init.d/php7.2-fpm start && nginx -g 'daemon off;'

Check environment variables now 🤩

Sign up to request clarification or add additional context in comments.

Comments

-3

It's possible that the naming convention, more specifically, the separator is causing the issue. Try naming your env var MY_VAR instead of MyVar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.