I want to exec() a bash script.sh from index.php.
When I run the script from terminal:
When I run the script from php:
I have changed httpd.conf:
USER
is not a magic variable that returns your username. It's just set for your convenience by login
, the program that authenticates interactive terminal logins.
From macOS man 1 login
:
The login utility enters information into the environment (see environ(7))
specifying the user's home directory (HOME), command interpreter (SHELL),
search path (PATH), terminal type (TERM) and user name (both LOGNAME and USER).
If you don't run in this context, these variables may not be available.
You should either update the bash script to get the username in a more robust way (id -un
), or you can do login
's work in PHP with putenv("USER=" . get_current_user());