下载mod_python  源码包

 git  clone  https://github.com/grisha/mod_python  

编译安装

cd   mod_python

#./configure  --help    查看编译的参数

yum  -y install  httpd-devel 

./configure --with-apxs=/usr/sbin/apxs --with-python=/usr/bin/python

make 

make   install_py_lib    

sudo make install  

make test   #测试,可以略过


修改apache 配置文件

vim  conf.d/python.conf 

LoadModule python_module modules/mod_python.so

Alias /py /var/www/html/py

<Directory /var/www/html/py>

AddHandler mod_python .py

PythonHandler mptest

PythonDebug On

</Directory>

编写一个测试文件

vim   /var/www/html/py/mptest.py

from mod_python import apache

def handler(req):

    req.content_type = 'text/plain'

    req.write("Hello World!")

    return apache.OK

保存退出

重启apache   

访问http://host/py/mptest.py  

返回"hello world!"  表示加载成功