If you say it works on the terminal and not on apache then apache’s php.ini
file may be disabling the use of shell_exec()
.
See http://www.php.net/manual/en/ini.core.php#ini.disable-functions
Your apache’s php.ini
file may look something like
disable_functions=exec,passthru,shell_exec,system,proc_open,popen
Remove shell_exec
from this list and restart the web server, although this is a security risk and I don’t recommend it.