1.安装flex(fast lex)
下载GNU Flex: flex-2.5.35.tar.gz
> tar zxvf flex-2.5.35.tar.gz
> cd flex-2.5.35
> ./configure --prefix=/usr/local/flex
> make
> sudo make install
2.安装python
下载Python-2.5.2.tgz
> tar zxvf Python-2.5.2.tgz
> cd Python-2.5.2
> ./configure --prefix=/usr/local/python
〉make
> sudo make install
3.安装mod_python
下载mod_python-3.3.1.tgz
> tar zxvf mod_python-3.3.1.tgz
> cd mod_python-3.3.1
> ./configure --with-apxs=/usr/local/apache/bin/apxs \
> --with-python=/usr/local/bin/python2.5 \
> --with-mutex-dir=/var/run/mod_python \
> --with-max-locks=32 \
> --with-flex=/usr/local/bin/flex \
> --with-python-src=/usr/src/python2.5
4. 配置Apache 服务器
> sudo vi /usr/local/apache/conf/httpd.conf
增加如下行:
LoadModule python_module libexec/mod_python.so
5. 测试
1) 建立测试目录
> cd /usr/local/apache/htdocs
> sudo mkdir test
2) 建立测试文件
> cd test
> sudo vi mptest.py
输入下面几行:
from mod_python import apache
def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK
3)配置测试目录
> sudo vi /usr/local/apache/conf/httpd.conf
增加如下几行:
<Directory /some/directory/htdocs/test>
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
4)重新启动apache服务器
> sudo /etc/init.d/apache restart
5) 浏览器访问
> w3m localhost/test/anyname.py
... Hello World!