apache利用mod_python整合

发布时间:2019-09-05 07:07:22编辑:auto阅读(1822)

    安装所需要的源码包: 
    •  Apache 2.2.22     (http://labs.mop.com/apache-mirror//httpd/httpd-2.2.22.tar.gz) 
    •  Python 2.7.3 (http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz) 
    •  Mod_python 3.3.1 (http://archive.apache.org/dist/httpd/modpython/mod_python-3.3.1.tgz) 
    •  Django 1.4        (https://www.djangoproject.com/download/1.4.1/tarball/) 

    安装步骤 
    1.  Apache安装 
    #tar -zxvf httpd-2.2.22.tar.gz 
    # httpd-2.2.22 
    # ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite 
    #make && make install 

    2.  Python安装 
    # tar -zxvf Python-2.7.3.tgz 
    #cd Python-2.7.3 
    # ./configure 
    #make && make install 
    #mv /usr/bin/python /usr/bin/python.bak 
    #ln -s /usr/local/bin/python2.7 /usr/bin/python 
    #python -V         #版本显示2.7.3 
        
    3.  django安装 
    # tar -zxvf Django-1.4.1.tar.gz 
    #cd Django-1.4.1 
    #python setup.py install            #执行没有报错,就说明安装成功 
    也可以检查是否成功 
    #python 
    >> import django                #这样import导入django模块没有报错,就安装成功 
        
    4.  mod_python安装 
    # tar -zxvf mod_python-3.3.1.tgz 
    # cd mod_python-3.3.1 
    #./configure \ 
    --with-apxs=/usr/local/apache2/bin/apxs \ 
    --with-python=/usr/local/bin/python2.7 
    #make             #执行make的时候会报错,如下:
    connobject.c:142: error: request for member ‘next’ in something not a structure or union    
    apxs:Error: Command failed with rc=65536    
    make[1]: *** [mod_python.so] Error 1    
    make[1]: Leaving directory `/root/django_python/mod_python-3.3.1/src'    
    make: *** [do_dso] Error 2

    解决办法: 
    编辑 /$home/mod_python-3.3.1/src/connobject.c 的 142 行: 
    !(b == APR_BRIGADE_SENTINEL(b) 
    改成: 
    !(b == APR_BRIGADE_SENTINEL(bb) 即:改成两个b 
    #make clean        
    #make && make install 

    5.  Apache    conf配置 
    1>.配置下httpd.conf,在这个文件里添加 
    LoadModule python_module modules/mod_python.so 
    另外我是开启了vhosts里面配置的,只需要将这行前面的#去掉 
    Include conf/extra/httpd-vhosts.conf 
    接着就是配置httpd-vhosts.conf文件,如下: 
    <VirtualHost *:80>    
           ServerName www.test.com    
           DocumentRoot "/data0/django/mysite"    
           <Location "/">    
                   SetHandler python-program    
                   PythonHandler django.core.handlers.modpython    
                   SetEnv DJANGO_SETTINGS_MODULE mysite.settings    
                   PythonAutoReload Off    
                   PythonDebug Off    
                   PythonPath "['/data0/django/mysite'] + sys.path"    
                   PythonInterpreter mysite    
           </Location>    
           <Directory "/data0/django/mysite">    
                   Order allow,deny    
                   Allow from all    
           </Directory>    
    </VirtualHost>
     
    重启apache,测试下。 
    大致就是这样的,你可以访问下面网址,有相关的资料: 
    http://blog.163.com/zhulp0372@yeah/blog/static/115894479201182134911490/ 
    http://www.cnblogs.com/oubo/archive/2012/04/06/2434961.html 
    http://djangobook.py3k.cn/2.0/chapter12/ 

关键字