I am trying to execute a python script from my PHP file. It was working locally (localhost), the code was:
$command = escapeshellcmd("python " . app_path(). "/http/controllers/machinelearning.py");
$result = shell_exec($command);
However I am getting an error when using python on the server:
shell_exec(): Unable to execute 'python'
If I send:
$command = "which python";
$result = shell_exec($command);
Then I get the echo "/usr/bin/python"
But using the path like:
$command = escapeshellcmd("/usr/bin/python " . app_path(). "/http/controllers/machinelearning.py");
$result = shell_exec($command);
gives the same error: shell_exec(): Unable to execute 'python'
I also tried passthru:
ob_start();
passthru($command);
$output = ob_get_clean();
Same result: passthru(): Unable to fork [python]
Executing python scripts work in the terminal, so I don't know why these commands don't work when called from the PHP script. Anyone had similar issues? I´ve been trying to find the answer all day.