On CentOS, I'm trying to pass an environment variable to a PHP script.
I've created this file, test.php:
<?php print_r($_ENV);
When I run this command:
DB=mysql php test.php
I get the following output:
Array
(
)
What did I miss?
Check your variables_order php.ini variable. It has to contain E for $_ENV to be populated. You can also do:
$ DB=whatever php -d variables_order=E -r 'echo $_ENV["DB"];'
whatever
Alternatively, you can use getenv() which will work regardless of the value of variables_order.
DBenvironment variable, there should be plenty of them.variables_orderand/or usegetenv(). Accessing the Unix environment variables (from a particular programming language, i.e., PHP) should be on-topic on SO... Though I wouldn't be surprised if there is a duplicate there.variables_orderand noticed that it does not populate$_ENVby default, I did not know that! I thought this config was only about populating the$_REQUESTvariable (and global variables in previous versions of PHP).$_ENVshould not be empty by default! Thanks for your help anyway, much appreciated.