Apache 2.2.17, Python 2.6, mod_python-3.3.1.win32-py2.6-apache2.2


系统平台:Windows XP sp2

软件包:Apache 2.2.17, Python 2.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:\Program Files\,安装后会得到D:\Program Files\Apache Software Foundation\Apache2.2目录
2.安装Python:
python-2.6.6.msi将其安装到D:\Program Files\Python26
3.安装 mod_python-3.3.1.win32-py2.6-apache2.2.exe,安装时能自动检测到python的安装目录,否则自己选择一下。另外,他会提示让选择Apache的配置文件目录,这里选择D:\Program Files\Apache Software Foundation\Apache2.2即可(这里注意最后一步目录选择)
4.配置Apache:在httpd.conf中的LoadModule部分下面添加如下:
LoadModule python_module modules/mod_python.so  
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/www">   
AddHandler mod_python .py   
PythonHandler hello   
PythonDebug On
SetHandler python-program    
</Directory>

ps:SetHandler python-program  一定要加

5.测试之前的准备(这个是个人喜好问题,可以不做):

       (1)在D:\Program Files\Apache Software Foundation\Apache2.2\下面新建目录www,并搜索httpd.conf中的下面两行:
DocumentRoot “D:/Program Files/Apache Software Foundation/Apache2.2/htdocs”
<Directory “D:/Program Files/Apache Software Foundation/Apache2.2/htdocs”>
将其改为:
DocumentRoot “D:/Program Files/Apache Software Foundation/Apache2.2/www”
<Directory “D:/Program Files/Apache Software Foundation/Apache2.2/www”>
以后,所有的代码,都会放到www下面。

       (2)将Apache的监听端口改为8080:搜索到“Listen”一行,将该行改为:

       Listen 8080
6.www目录下新建文件hello.py,内容如下:

from mod_python import apache   
  
def hello_handler(req):   
    req.write("This is a 'Hello World' from mod_python !")   
    return apache.OK
7.在浏览器中输入:
http://localhost:8080/hello.py
得到了类似下面的结果:
This is a 'Hello World' from mod_python !

你可能感兴趣的:(apache,windows,python,XP,软件测试)