The reason I start to learn Python is to play with Google App Engine. So I think I should learn Python web programming. I need to add Python support to my Apache server. Someone recommanded me to use “mod_python”. But unfortunately I can’t install the mod_python correctly. Therefore, I have to use Python CGI.
Adding Python CGI support is very simple. You don’t need to download other things. An Apache HTTP server and a Python package are enough. For instance, I installed the Python in E:Python22. So the Python interpreter is E:Python22python.exe. This is important for the CGI scripts. Next, open Apache’s httpd.conf to configure the web server. I set the DocumentRoot to “D:/Web”, so I find
Options Indexes FollowSymLinks
in the section <Directory “D:/Web”>…</Directory>. Then add “ExecCGI” to make all the directories can run CGI programs.
Options Indexes FollowSymLinks ExecCGI
Search “AddHandler cgi-script”. Change the line into:
AddHandler cgi-script .cgi .py
to tell Apache the *.py files are CGI programs.
Now you can create a “Hello World” programming on your DocumentRoot directory. For example, D:Webmptest.py that contains:
#!E:Python22python.exe print "Content-type: text/plainn" # Mustn't omit the "n" character. Otherwise, it will make 500 Error. print "hello world"
Open your browser and visit http://localhost:8080/mptest. A “Hello World” will appear.
Tags: Programming, Python