Search code examples
phppythonvirtual

PHP's virtual() command causes raw Python code to display on the webpage instead of executing it


I'm using this command to execute a Python script from who.php:

virtual('../cgi-bin/sigphon/who.py');

on an Apache server, but when I go to the webpage from which command is called (who.php), raw code from the Python file is displayed, like this:

\#!/usr/bin/python print '3' scriptpath = "/compsci/webdocs/morphon/web_docs/cgi-bin/sigphon" import sys, cgi, string, sha, time import cgitb sys.path.insert(0, scriptpath) import easyhtml, member, readdb, common cgitb.enable() # FieldStorage object to hold the form data formdata = cgi.FieldStorage() thisscript = "%s/who.py" % (common.cgibase) def update_text(): return """

etc. ...

I'm able to execute the who.py script from the command line on the same server, from the same directory as who.php, with no issues, and I've tried setting the permissions for all files involved to 777.

I've also tried

echo exec('../cgi-bin/sigphon/who.py');

but to no avail. What's going on here?


Solution

  • You would have to configure Apache to parse .py files using python. There is a mod_python for Apache or you can set it up to run under CGI.

    Most likely you can just use one of the PHP Program Execution Functions.

    passthru('/path/to/python ../cgi-bin/sigphon/who.py');