Reputation: 611
i've wampserver with apache 2.4.4 installed in
I've installed python and i created a test file :
#!/Python34/python
print "Content-type: text/html"
print
print "<html><head>"
print ""
print "</head><body>"
print "Hello."
print "</body></html>"
i wanna know how to run this script ?
Upvotes: 0
Views: 708
Reputation: 5867
+1 to what Julien Palard says about not using CGI, it's really slow and inefficient. An alternative to running your server standalone and proxying through to it using Apache is to use mod_wsgi, which allows you to run Python processes inside the Apache process. Most web frameworks (Django, Bottle, Flask, CherryPy, web2py, etc) work well with it.
Upvotes: 0
Reputation: 11626
I personally don't like the way CGI and all this stuff work (slow to spawn processes, need to use some kind of tricks like "fastcgi" to bypass this, etc...)
I think you may build your Python programm as an HTTP server (Use cherrypy for example, or whatever you want.), start your Python program to listen on localhost:whatever, then, from the Apache side, just configure a proxy to localhost:whatever.
Pros:
Configuring apache 2 to pass your requests to your python daemon is as easy as:
<VirtualHost *:80>
ServerName example.com
ProxyPass / http://localhost:8080/
</VirtualHost>
And an hello world from the cherrypy documentation:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
Upvotes: 1