Now I know this question has been asked a few times, but I've followed everyone's suggestions and I'm still stumped.
I have a shell script (/var/www/scripts/test.sh):
ssh_con="[email protected]"
key="/home/user/.ssh/key"
echo "export start"
ssh -i $key $ssh_con "php /file/location/ service:batch:job export --env=prod"
echo "export complete"
the script has the following permissions:
-rwxrwxrwx 1 www-data www-data 1792 Jun 3 10:44 bash_script.sh*
the code im running in php is:
try {
$outbuf=shell_exec("sh /var/www/scripts/test.sh");
echo "<pre>".$outbuf."</pre>";
}catch (Exception $e) { //while an error has occured
echo "==> Error: ".$e->getMessage();
exit();
}
When I view this from a web browser I get:
export start
export complete
However, ssh does not run.
I can confirm that php.ini allows exec and shell_exec.
I feel like I'm missing something obvious.
putenv("PATH", "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin");before you callshell_exec();.