I am trying to create a tmux session and run a few other commands in it via php.
When i run the script from web it will not execute the commands, but when i run the script from terminal with "php test.php" it works.
I have tried to run the cmds as sudo and turn off the sudo pass for www-data. But still the commands won't execute.
Script:
$array_output = array();
$cmd = "sudo tmux new-session -s Server-17 -d ENTER 2>&1";
$output = shell_exec($cmd);
array_push($array_output, $output);
$cmd = "sudo tmux send -t Server-17 'cd /home/Minecraft/Servers/1/17/' ENTER 2>&1";
$output = shell_exec($cmd);
array_push($array_output, $output);
$cmd = "sudo tmux send -t Server-17 'chmod +x start_script.sh' ENTER 2>&1";
$output = shell_exec($cmd);
array_push($array_output, $output);
$cmd = "sudo tmux send -t Server-17 'sh start_script.sh' ENTER 2>&1";
$output = shell_exec($cmd);
array_push($array_output, $output);
var_dump($array_output);
Output:
array (size=4)
0 => null
1 => string 'failed to connect to server
' (length=28)
2 => string 'failed to connect to server
' (length=28)
3 => string 'failed to connect to server
' (length=28)