I have a Python3 Pyro4 server client app that works great when run from command line.
server.py
import Pyro4
@Pyro4.expose
class JokeGen(object):
def __init__(self):
self.jokevar = "Joke"
def joke(self, name):
return "Sorry "+name+", I don't know any jokes."
def main():
Pyro4.Daemon.serveSimple(
{
JokeGen: "example.jokegen"
},
ns = True)
if __name__=="__main__":
main()
client.py
#!/usr/bin/env python3
import Pyro4
import sys
person_to_joke = sys.argv[1]
joke_control = Pyro4.Proxy("PYRONAME:example.jokegen")
print (joke_control.joke(person_to_joke))
The problem is I need to run the client from a web app using PHP.
I have created a joke.php
<?php
$command = escapeshellcmd('/full/path/to/client.py SquirrelMaster');
$output = shell_exec($command);
echo $output;
?>
While this code does actually work I did some non-standard hacking to make it work. I took a copy of my /home/user/.local (where the pyro4 modules have been installed for user) and placed it in /var/www/ and gave ownership to www-data.
sudo chown -R www-data.www-data /var/www/.local
It seems like there must be a better way to do this and I'm pretty sure there will be potentially issues in the future if I leave things this way. The issues seems to be that the Pyro4 modules need to be available for the www-data user. So my question is, What is the proper way to make Pyro4 modules available to the www-data user on Ubuntu linux running apache2?
EDIT - ADDITION
I also tried doing the following:
sudo mkdir /var/www/.local
sudo mkdir /var/www/.cache
sudo chown www-data.www-data /var/www/.local
sudo chown www-data.www-data /var/www/.cache
Then run the command:
sudo -H -u www-data pip3 install pyro4 --user www-data
But this results the error "Could not find a version that satisfies the requirement www-data (from versions: ) No matching distribution found for www-data"
sudo -H -u www-data pip3 install pyro4
does the job. That extra--user www-data
was causing the problem. I am NOT changing the permissions for /var/www. I'm creating /var/www/.local and /var/www/.cache and giving www-data permissions for those folders ONLY. If you would like to update your answer with this solution then I will give you credit for coming up with an acceptable answer. You have been very helpful! Thank You!!!! :) – Andraandrade