0

I have next result of command sudo -u www-data echo $PATH in terminal:

/home/denis/node-v0.12.0/bin:/home/denis/node-v0.12.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

I have next result in PHP if I run command echo `echo \$PATH`:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

PATH in terminal and in PHP is different. I don't understand why.

FiftiN
  • 733
  • 1
  • 7
  • 23

1 Answers1

2

Running the command literally as given

sudo -u www-data echo $PATH

the $PATH is expanded by your shell before doing a sudo (and show your $PATH). However, if you quoted this properly, it could be deferred into the sudo'd user, and expose a different problem.

Unless you make special provision for this (an option to sudo, which may/may not work), environment variables such as PATH are reset to system defaults when using sudo. For further discussion see

Community
  • 1
  • 1
Thomas Dickey
  • 43,185
  • 7
  • 51
  • 88
  • I have changed PATH in PHP according this topic: http://stackoverflow.com/questions/19696230/how-to-set-global-environment-variables-for-php – FiftiN Apr 05 '15 at 09:24