I am running many python scripts from PHP. My php script template as below:
<?php
setlocale(LC_ALL, "en_US.utf8");
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
$command = escapeshellcmd("/usr/bin/python2.7 /path/to/script");
$args = escapeshellarg($_GET["title"]). " " .
escapeshellarg($_GET["user"]);
$output = shell_exec($command . " " . $args);
echo $output;
But now I need to run some python scripts which are in virtual environment.
I tried to replace /usr/bin/python2.7
with ./www/python/venv/bin/python3
, but it does not work.
So how to run it in PHP?