I'm trying to call a Python script from a webpage, and apache2 is not actioning the script. The files are:
test.py
#!/usr/bin/env python
print "Content-type: text/html\n\n"
print "<h1>Hello World</h1>"
index.html
<form action="./test.py" method="POST">
<input type="text" size="70" name="data" value=""><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
I've enabled a2enmod cgi and edited apache settings as follows:
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
...
<directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler cgi-script .py
Require all granted
</directory>
</VirtualHost>
Webpage files ownerships are:
# ls -lh /var/www/html/
total 16K
-rw-r--r-- 1 root root 342 May 30 13:34 index.html
-rwxr-xr-x 1 root root 88 May 30 14:11 test.py
Running apachectl -M brings up a list with line cgid_module (shared).
When I bring up the page I can see the form, but when I click 'Submit' the browser either prompts to download test.py (FF) or views it (Chrome). Any idea what I'm getting wrong here?
Ctrl+Shift+Jand check the network tab and the returned content-type of your py script. What does chrome say you're getting, text/plain file? I'm guessing you've reloaded the servers configuration?documentand there for py script isn't registered as a handler. Have a look at httpd.apache.org/docs/2.4/mod/mod_mime.html for now/usr/lib/cgi-bin? What does apache say in the logs? Just to be clear changing the mime type manually won't make the script execute, just to show you why you're getting document :)<directory..>to/var/www/html..