首页 > 代码库 > apache mod_python 安装

apache mod_python 安装

环境:Linux 2.6.32-431.23.3.el6.i686

 

1、安装python

wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz 
tar zxf Python-2.7.1.tgz 
./configure --prefix=/usr/local/services/Python-2.7.1
make
make install

 

2、安装httpd(apache)

http://down1.chinaunix.net/distfiles/httpd-2.0.59.tar.bz2 
tar jxf httpd-2.0.59.tar.bz2 
./configure --prefix=/usr/local/services/httpd-2.0.59 --enable-rewrite --enable-so 
make
make install

 

3、安装mod_python

wget http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.0b.tgz mod_python-3.3.0b.tgz
tar zxf 
./configure \ 
--prefix=/usr/local/services/mod_python-3.3.0b \ 
--with-apxs=/usr/local/services/httpd-2.0.59/bin/apxs \ 
--with-python=/usr/local/services/Python-2.7.1/bin/python2.7
make
make install


出现错误:mod_python only works with Apache 2. 
编译不正确时一定要仔细看帮助文档(./configure --help),这样可以节省很多时间
 

4、配置apache(httpd.conf)

4.1、load module
LoadModule python_module modules/mod_python.so
#(80已被占用)
Listen 8080
4.2、configure handle python
在根目录(<Directory "/usr/local/services/httpd-2.0.59/htdocs">)指令下添加
SetHandler mod_python
PythonHandler test
PythonDebug On
4.3、重启httpd
 /usr/local/services/httpd-2.0.59/bin/apachectl restart

5、验证 

5.1、在 /usr/local/services/httpd-2.0.59/htdocs 下添加 test.py脚本
from mod_python import apache
def handler(req):
    req.write("hello world!")
    return apache.OK
5.2、浏览器输入:http://192.168.44.129:8080/test 显示:

 

apache mod_python 安装