I want to use php's exec() function on an ubuntu server. The problem is, I alway get an error, that the command is not found. For example using
exec("echo 123");
prints
sh: /echo: not found
To me, it looks like php is using the sh shell, when I want to be using bash. I tried changing the shell for www-data in /etc/passwd, that didn't help either.
Does anybody have an idea where else the problem might be coming from or how I can change the shell for php's ubuntu user.
Thanks, Timo
[EDIT]
Maybe this helps:
I call a bash script from ssh as timo, this script calls a php script, which uses exec. I know, it sounds weird, but it's part of a bigger development environment...
The point is, I'm not ever certain, as which user the script inside exec is executed.
[EDIT]
By now I figured out that there must be another rights problem involved. Even if I try calling a bash script test.sh (by it's full path!) from within exec, php test.php will just say.
sh: /test.sh: not found
Try shell_exec() instead. exec should not invoke ANY shell to execute your program. Alternately, you can invoke bash with exec like
exec("/bin/bash -c \"echo $foo > bar.txt'\"")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With