您的位置:首页 > 编程语言 > Python开发

mod_python安装及问题解决

2011-09-28 08:49 1241 查看
一、先下载一份最新版本的mod_python,当前最新版是3.3.1版:

wget http://apache.mirror.phpchina.com/httpd/modpython/mod_python-3.3.1.tgz
这里要注意,只有最新版本才支持2.2.2以上的apache。

二、解包,安装:

tar xzvf mod_python-3.3.1.tgz

cd mod_python-3.3.1

./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/python251/bin/python --with-max-locks=32 --with-python-src=/soft/Python-2.5.1/ --with-flex=/usr/bin/flex

make

make install

在make install的过程中,有可能出问题,我就是在那一步卡住了,结果害我多折腾了半天,报错如下:

/usr/bin/install -c -d /usr/local/apache/modules

/usr/bin/install -c src/mod_python.so /usr/local/apache/modules

/usr/bin/install: stat‘src/mod_python.so’失败: 没有那个文件或目录

make[1]: *** [install_dso] 错误 1

make[1]: Leaving directory `/soft/mod_python-3.3.1'

make[1]: Entering directory `/soft/mod_python-3.3.1'

cd dist && make install_py_lib

一开始还以为是mod_python和apache 2.2.2不兼容,在网上找资料找了半天,最后在mod_python官方网站找到这样一篇文章:

4.1. src/mod_python.so: No such file or directory

When running “make install” I get this:

# make install

[snip]

Performing DSO installation.

/usr/bin/install -c src/mod_python.so /usr/local/apache2/modules

/usr/bin/install: cannot stat `src/mod_python.so’: No such file or directory

make[1]: *** [install_dso] Error 1

make[1]: Leaving directory `/home/hobb/mod_python-3.0.1′

make: *** [install] Error 2

#

This is a problem with libtool. Apache comes with its own copy of libtool, and the version which comes with Apache 2.0.43 is old for some reason. To fix this problem, you need to first make sure that you a have a recent libtool (”libtool –version” should show
1.4.2 or later), then recompile Apache by first rerunning ./buildconf like this:

$ ./buildconf

$ ./configure –your-config-args

$ make clean ; make

$ make install

And finally rebuild mod_python with

$ ./configure

$ make clean ; make

文章上说是libtool版本太旧的原因,他们给出的解决方案是:重新编译apache,当时我脑子也没有转过弯来,傻乎乎地直接照着他们说的重新编译,折腾半天,问题依旧,只好继续Google,最后在一个法文站点上看到了一个让我差点当场崩溃的答案,最简单的方法是这样的:

mv /usr/local/apache/build/libtool /usr/local/apache/build/libtool.old

ln -s /usr/bin/libtool /usr/local/apache/build/libtool

方才明白,自己走了多少弯路,其实只要link一下libtool就可以了!看来mod_python的官方网站也该检讨一下他们的文档了!当然,由此得出的教训也很深刻,那就是:谨慎求解,别急于求成!

三、配置httpd.conf,使之支持python程序。

cd /usr/local/apache/conf

vi httpd.conf

添加:

LoadModule python_module modules/mod_python.so

创建一个虚拟主机:

AllowOverride All

Options Indexes Foll
4000
owSymlinks MultiViews

Order allow,deny

Allow from all

ServerAdmin webmaster@handaoliang.cn

DocumentRoot /home/handaoliang/web/python

ServerName www.handaoliang.cn

ErrorLog logs/handaoliang_cn-error_log

CustomLog logs/handaoliang_cn-access_log common

然后,在此虚拟主机上加上如下三行代码:

SetHandler mod_python

PythonHandler mod_python.publisher

PythonDebug On

完成后是这个样子:

AllowOverride All

Options Indexes FollowSymlinks MultiViews

Order allow,deny

Allow from all

#允许执行python程序

SetHandler mod_python

PythonHandler mod_python.publisher

PythonDebug On

ServerAdmin webmaster@handaoliang.cn

DocumentRoot /home/handaoliang/web/python

ServerName www.handaoliang.cn

ErrorLog logs/handaoliang_cn-error_log

CustomLog logs/handaoliang_cn-access_log common

写一个脚本,测试一下:

def index():

  return "Welcome
to handaoliang.cn"

如果一切正常,当访问http://www.handaoliang.cn时,应该会显示:Welcome to handaoliang.cn的字样。

参考资料:

Mod_python Manual:http://www.modpython.org/live/current/doc-html/

转自:http://www.handaoliang.com/article_33.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息