I'm trying to call a Python script from a PHP file, but it fails when I have to load a local library. My PHP is able to call my python if it doesn't load local libraries, and my python script works when launched manually.
Here are minimal (non) working files :
index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<?php
$command = escapeshellcmd ("./getter.py") ;
$output = shell_exec ($command) ;
echo "<p>$output</p>" ;
?>
</body>
</html>
getter.py
#!/usr/bin/env python2
import got
if __name__ == "__main__" :
print "Python2 working"
Where got
is the famous local library.
When I manually launch my ./getter.py
the print is happening, but my webpage doesn't display anything.
When I comment the import got
the webpage is also displaying the print.
Additional information :
os
, csv
, or others)$command = escapeshellcmd ("./getter.py") ; $output = shell_exec ($command) ;
by a simple $output = shell_exec ("./getter.py") ;
#!/usr/bin/env python2
by #!/usr/bin/python2
/var/html/www/test
, as planned.Here is a folder tree :
├── getter.py
├── got
│ ├── __init__.py
│ ├── manager
│ │ ├── __init__.py
│ │ ├── TweetCriteria.py
│ │ └── TweetManager.py
│ └── models
│ ├── __init__.py
│ └── Tweet.py
├── index.php
├── __init__.py
└── lib
├── __init__.py
└── toto.py
Thank you much.
This was actually caused by a dependency problem. Some required libraries where installed only for some users. And Nginx couldn't access it as root, while the normal user could.