Python script is not running when "pymongo" import is included during execution from php script with "shell_exec"?

25 Views Asked by At

I have a python script that starts like that:

print("Start...")
import pymongo
import json

I also have the following .php file:

<html>
<body>

<?php
  echo "Start <br>";
  $command = escapeshellcmd("python3 myScript.py");
  $output = shell_exec($command);
  echo $output;
?>

</body>
</html>

When I run the php script from browser only "Start" is displayed. Execution does not completed. When I remove "import pymongo", the python script runs completely. Why does this happen?

I use ubuntu 20.04.5 LTS VM in ESXI, Php v.7.4.3, MongoDB shell version and server version 5.0.13, MongoDB extension v.1.6.1 for php and pymongo v.3.12.0.

I tried using chmod for python file and chmod 777 for the folder containing the .py file, but not result. Also, when I run the .py file with "pymongo" import from terminal, works perfectly.

0

There are 0 best solutions below