标题:apache2.55+mod_python2.82+Django0.91配置手册(NT) 出处:运维进行时 时间:Tue, 14 Aug 2007 22:30:42 +0000 作者: 地址:https://blog.liuts.com/post/10/ 内容: 1、 安装APACHE,安装目录随便定,我这里用apache_home表示apache的安装根目录,安装完毕后,启动 apache,看到apache的欢迎界面,则说明apache安装成功 2、 安装python2.4.2, 默认安装在c盘下面(可以随意指定),设置环境变量, 引用 pythonpath=.;C:\Python24\Lib;C:\Python24\dlls;C:\Python24\libs pythonhome=C:\Python24 path环境变量中加入C:\Python24;C:\Python24\Scripts; 进入系统命令提示行,输入python,出现如下信息: Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 说明python安装成功 3、 安装mode_python,直接执行mod_python-3.2.8.win32-py2.4.exe,默认安装,会出现对话框让你选择 apache的根目录,选择正确后,会在apache_home/modules目录下生成一个mod_python.so的文件, 安装完毕后,修改apache的配置文件http.conf,进行如下配置: LoadModule python_module modules/mod_python.so Order allow,deny Allow from all setHandler python-program PythonHandler mptest PythonDebug On 并在编辑器中编写mptest.py文件: from mod_python import apache def handler(req): req.content_type = 'text/plain' req.write("Hello World!") return apache.OK 保存mptest.py到apache_home/htdocs目录下, 启动apache,在浏览器中输入http://localhost:8080/mtest.py 出现 Hello World! 页面,说明mod_python安装成功. 4、 安装Django0.91,下载Django0.91后,打开命令提示行,进入Django0.91的目录,执行 python setup.py install 安装后,随便在一个目录,比如我在d:/python/example目录下,打开命令提示行,并进入该目录,执行 django-admin.py startproject newtest 该命令会在examply目录下生成一个test的目录,并在test目录下生成了四个文件: __init__.py,settings.py,urls.py,manage.py 启动django自带的web server,命令行中执行:manage.py runserver,会出现如下提示: Validating models... 0 errors found. Django version 0.9.1 (magic-removal), using settings 'newtest.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows). 在浏览器中输入http://loalhost:8000/,有一个欢迎祝贺的页面,说明安装django成功了。 5、 修改apache的配置文件http.conf如下: DocumentRoot "e:/python/newtest" Order allow,deny Allow from all setHandler python-program PythonPath "['d:/python'] + sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE newtest.settings PythonDebug On 将DirectoryIndex注释掉 保存后, 将limodou写的教程里的第三讲例子来进行测试(你可以自己写例子来测试) 有一些注意事项,比如说路径问题,教程里的第十二讲已经说的很清楚了. 我这里只是 把一些不同的配置讲一下. 另外如果按照第三讲例子来进行测试,可能会有个类似这样的错误提示:(无需修改) 引用 Mod_python error: "PythonHandler django.core.handlers.modpython" Traceback (most recent call last): File "../site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "../site-packages/django/core/handlers/modpython.py", line 165, in handler return ModPythonHandler()(req) File "../site-packages/django/core/handlers/modpython.py", line 126, in __call__ os.environ.update(req.subprocess_env) File "../python2.4/lib/os.py", line 478, in update self[k] = dict[k] File "../python2.4/lib/os.py", line 463, in __setitem__ putenv(key, item) TypeError: putenv() argument 2 must be string, not list 可以修改modpython.py的ModPythonHandler函数: class ModPythonHandler(BaseHandler): def __call__(self, req): for envks,envval in req.subprocess_env.items(): envvalscopy = req.subprocess_env[envks] if type(envvalscopy) == list: req.subprocess_env[envks] = envvalscopy[0] # mod_python fakes the environ, and thus doesn't process SetEnv. This fixes that os.environ.update(req.subprocess_env) 就可以了。 Generated by Bo-blog 2.1.1 Release