0

I have php script which uses some environment variables using getenv from /etc/environment. It works fine when I run it from terminal using php command. But environment variables are not getting when running same script from nohup on terminal.

PHP is 5.3 using Debian 6.

user1551373
  • 131
  • 1
  • 3
  • 5

1 Answers1

0

I have no problem:

nohup php -r 'var_export(getenv("PATH"));'

Same result with

php -r 'var_export(getenv("PATH"));'

Maybe you are talking with user env var ?

MY_VAR=42;
nohup php -r 'var_export(getenv("MY_VAR"));'
# The output will return false.
# You need to use export


export MY_VAR=42;
nohup php -r 'var_export(getenv("MY_VAR"));'
ImmortalPC
  • 1,650
  • 1
  • 13
  • 17
  • I have environment variable named DATABASE_URL in /etc/envirment file. And in my php code I am accessing it like $db = getenv('DATABASE_URL'). It does work when I run script like php script.php but not when I run it like nohup php script.php& – user1551373 Aug 23 '13 at 13:29
  • And using you second example with export, I am still getting false. Is there anything settings I need to change in php or debian config? – user1551373 Aug 23 '13 at 13:47
  • On Ubuntu and Debian I get the correct result... event with export and /etc/environment – ImmortalPC Aug 23 '13 at 15:49