PHP exec $PATH variable missing elements

后端 未结 3 1263
春和景丽
春和景丽 2020-11-27 07:59

When I echo $PATH on my command line, it returns

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/MAMP/Library/bin:/usr/local/git/bi         


        
相关标签:
3条回答
  • 2020-11-27 08:26

    Environment variables on Mac OS X are set by differing mechanisms depending on how your code, or its parent process, was launched. To insure that items launched from an interactive shell and items launched by the WindowServer have the same path, you need to keep ~/.MacOSX/environment.plist in sync with what is set in .profile (or .cshrc).

    0 讨论(0)
  • 2020-11-27 08:37

    What does:

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

    give you?

    It's likely the shell that PHP spawns (probably sh instead of bash) isn't getting the same environment that you have at the command line. You don't say how you're running your exec command.

    This will show you which shell is being run:

    php -r 'echo shell_exec("echo $0");'
    

    You may need to use the putenv command or determine whether your path needs to be set in /etc/profile, ~/.profile or ~/.bashrc in order for it to be picked up.

    0 讨论(0)
  • 2020-11-27 08:42

    Try executing this before you call exec:

    putenv("PATH=" .$_ENV["PATH"]. ':/usr/local/git/bin:/usr/X11/bin');
    
    0 讨论(0)
提交回复
热议问题