Python – cgi and python script files are downloading from server instead of executing there

cgipython

I kept some cgi,python files under /var/www/cgi-bin and trying to execute
I followed all the steps in:

http://webpython.codepoint.net/cgi_tutorial

Still i am not able to execute. when i enter 192.168.1.191/cgi-bin/sample.py or 192.168.1.191/cgi-bin/example.cgi , I am getting the file download pop-up.

Do i need to make any other changes other than that showed in link.

Best Answer

What system are you on? I have a VM running arch linux which I am using for CGI development using python, so I simply edit the file: /etc/lighttpd/lighttpd.conf and add the following:

server.modules          =(
                    "mod_cgi"
                    )
cgi.assign              =(
                    ".cgi" =>"/usr/bin/python",
                    ".sh" =>"/bin/sh"
                    )

A quick explaination of what is going on above: the first three lines are just telling the server to enable its cgi module. The last four lines are telling the cgi module which environment should be used to execute a given file extension. In my case, *.cgi files are assigned to python by putting the path to the proper python executable in quotes after the =>

Does this help?