Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a hello world script written in python called hello.py. I am using apache on a windows machine, and I'd like the script to run automatically, whenever I enter something like http://localhost/

Can someone please tell me how to do this ?

PS: If I point to the script directly from the browser, it displays properly.

hello.py:

#! c:\Python27\python.exe

print "Content-Type: text/html\n\n"
print 'Heya, world..yaba daba doo!'
share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

It sounds like you want your Python script to be the index document?

If your setup already works when you do something like http://localhost/hello.py I would suggest renaming it to index.py (common convention to call an index document "index.something") and then editing your Apache configuration to include index.py inthe DirectoryIndex filenames list.

share|improve this answer
add comment

I'd highly recommend you write your app (however simple) around a framework. It makes everything massively easier, and you don't end up reinventing wheels. I tend to use Django, or CherryPy.

I recommend you give Cherry a look. The homepage details how to make a Hello World application.
Then all you need to do is ProxyPass to it from Apache, or use mod_wsgi and let apache communicate directly with the application.

share|improve this answer
add comment

Is your DirectoryIndex set appropriately in your httpd.conf file?

For example, my DirectoryIndex line is as follows - you should add hello.py to the list (although index.py may be more conventional).

DirectoryIndex index.php index.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.