PHP Command line interface, set and read ENV variables

When a variable on the console is set

export VARIABLE=VALUE;

You can get it from PHP Command line (CLI) using

getenv(‘VARIABLE’)

 

Example

#script.php
<?php
var_dump(getenv('VAR'));
?>

From command line

php -f script.php //bool(false)
export VAR=a; php -f script.php //string(1) "a"