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
I think PHP calls /bin/sh internally (or cmd.exe on Windows) regardless of which function you use.
Running ls -l /proc/$$/exe | sed 's%.*/%%'
in your terminal in a Linux system should tell you what shell you're using, which is bash in my Ubuntu terminal by default. If you run the following in Ubuntu:
<?php
exec('ls -l /proc/$$/exe | sed \'s%.*/%%\'', $res);
// or:
//$res = shell_exec('ls -l /proc/$$/exe | sed \'s%.*/%%\'');
echo(json_encode($res));
you will get ["dash"] as the result, regardless of which function you use. If you change /bin/sh to point to bash rather than dash, the result from PHP changes to bash, but I don't recommend doing that obviously.
So long story short it's probably not possible to change this without modifying your entire server's default shell or compiling PHP from source.
If you want to solve the mystery further, it's probably related to ext/standard/proc_open.c and ext/standard/exec.c (all these functions are in there, system, passthru, etc.) in the PHP source, but to be honest it beats me.
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 what you want to do is:
/usr/bin/mysql --user=asdf --password=asdf mydb < ./dump.sql
Then I imagine this would work (regardless of shell):
/usr/bin/mysql --user=asdf --password=asdf mydb < /full/path/to/dir/dump.sql
I think the problem is that there is no $PATH setup. Try using full paths to your binaries ie /bin/echo