Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a test script, /var/www/etym/cgi-bin/test.py

#!/usr/bin/python 
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

print "Content-Type: text/plain;charset=utf-8"

print "Hello World!"

And I'm trying to run it by going to http://localhost/etym/cgi-bin/test.py in my browser, but it's not working--Firefox just asks me whether I'd like to open the file with gedit or save it to the disk. What do I need to do to get it to run? I already ran chmod +x on the script.

share|improve this question
    
Could you explain what your requirements are? Most people use wsgi for Python nowadays or simply a framework to build the applications in. Do you really need to do it plain CGI or...? And what web server are you using? (You probably don't want to run one, or you want a wsgi module for you web server.) –  gertvdijk Aug 26 '13 at 19:21
    
I just want to be able to run a simple python script on a web server. I'm just using the standard apache2 that comes with ubuntu and the stock configuration. I don't know the difference between cgi and wsgi, and so I'm not married to CGI, but I don't want to have to configure a big framework, apache modules, or other complicated things just to be able to see "Hello World" in my browser window. –  Jon Aug 26 '13 at 19:33
    
You can try flask (flask.pocoo.org/docs/quickstart/#quickstart) for simple python "hello world" web scripts. –  pondohva Aug 26 '13 at 20:17
    
"/var/www/etym/cgi-bin/test.py" please put those files OUTSIDE your webroot. –  Rinzwind Apr 29 at 14:59
add comment

1 Answer 1

up vote 1 down vote accepted

Make sure you have configured your webserver properly to run CGI scripts.

Refer this for more info: https://httpd.apache.org/docs/2.4/howto/cgi.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.