Apache 2.2.17, Python 2.6, mod_python-3.3.1.win32-py2.6-apache2.2
系统平台:WindowsXPsp2
软件包:Apache2.2.17,Python2.6,mod_python-3.3.1.win32-py2.6-apache2.2
1.安装Apache:
将httpd-2.2.17-win32-x86-openssl-0.9.8o.msi安装到D:\ProgramFiles\,安装后会得到D:\ProgramFiles\ApacheSoftwareFoundation\Apache2.2目录
2.安装Python:
python-2.6.6.msi将其安装到D:\ProgramFiles\Python26
3.安装mod_python-3.3.1.win32-py2.6-apache2.2.exe,安装时能自动检测到python的安装目录,否则自己选择一下。另外,他会提示让选择Apache的配置文件目录,这里选择D:\ProgramFiles\ApacheSoftwareFoundation\Apache2.2即可(这里注意最后一步目录选择)
4.配置Apache:在httpd.conf中的LoadModule部分下面添加如下:
LoadModulepython_modulemodules/mod_python.so
<Directory"C:/ProgramFiles/ApacheSoftwareFoundation/Apache2.2/www">
AddHandlermod_python.py
PythonHandlerhello
PythonDebugOn
SetHandlerpython-program
</Directory>
ps:SetHandlerpython-program一定要加
5.测试之前的准备(这个是个人喜好问题,可以不做):
(1)在D:\ProgramFiles\ApacheSoftwareFoundation\Apache2.2\下面新建目录www,并搜索httpd.conf中的下面两行:
DocumentRoot“D:/ProgramFiles/ApacheSoftwareFoundation/Apache2.2/htdocs”
<Directory“D:/ProgramFiles/ApacheSoftwareFoundation/Apache2.2/htdocs”>
将其改为:
DocumentRoot“D:/ProgramFiles/ApacheSoftwareFoundation/Apache2.2/www”
<Directory“D:/ProgramFiles/ApacheSoftwareFoundation/Apache2.2/www”>
以后,所有的代码,都会放到www下面。
(2)将Apache的监听端口改为8080:搜索到“Listen”一行,将该行改为:
Listen8080
6.www目录下新建文件hello.py,内容如下:
frommod_pythonimportapache
defhello_handler(req):
req.write("Thisisa'HelloWorld'frommod_python!")
returnapache.OK
7.在浏览器中输入:
http://localhost:8080/hello.py
得到了类似下面的结果:
Thisisa'HelloWorld'frommod_python!