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