How Do I Properly Call A Python Pyro Client Using Php And Apache Web Server?
Solution 1:
Looks a bit like this question https://superuser.com/questions/646062/granting-write-permissions-to-www-data-group
I wanted to suggest using the PYTHONPATH environment variable to point to a library install location readable by the www-data user where you'd copy the python modules it needs to acces, but I think this is considered bad form nowadays.
Probably best is to create a Python Virtualenv that is accessible for the www-data user and install all required modules into that, using the pip command from that virtualenv. You may have to use some sudo/chown dance to get this right still.
Another way perhaps is to not bother with calling a python subprocess at all, but use Pyro's HTTP gateway. That way you can simply do a HTTP request from PHP to a locally running Pyro http gateway process, which will translate it into a proper Pyro call. I don't know PHP but it seems to me that it should be easy to make a custom http request to a server running on some localhost port. This may be faster as well because you're not starting up python processes for every call.
(edit): another succesfully working solution seemed to be the following, where sudo is used to invoke pip under the appropriate user, letting it install the library into www-data
's .local library folder:
- create
/var/www/.local
and/var/www/.cache
folders, givingwww-data
permissons to these folders only (and not/var/www
to avoid security issues) - invoke
sudo -H -u www-data pip3 install pyro4
You may still need to add--user
to the pip command if it's an older version, because I think that only recent pip versions install to the user's lib folder by default instead of to the global system python's lib folder.
Post a Comment for "How Do I Properly Call A Python Pyro Client Using Php And Apache Web Server?"