apache下安装python模块运行django站点框架

2011年12月16日 发表评论 阅读评论

安装django
直接rpm包和yum方式两种方式
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

yum update
yum install mod_python Django
安装数据库支持
sqlite、PostgreSQL 和mysql,分别如下:
yum install python-sqlite2
yum install python-psycopg2
yum install python-devel mysql-devel gcc wget python-setuptools
或者源码包安装,这里只介绍mysql一种
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
tar -zxvf MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3/
python setup.py build
python setup.py install
配置apache虚拟主机;
<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
    PythonDebug Off
</Location>
如果你想你的Django应用程序存储在另一个位置,需要给其指定一个路径在上面的配置中
PythonPath "['/srv/www/brackley.net/application'] + sys.path"
如下,是一个站点为361way.com站点的配置文件
<VirtualHost 361way.com:80>
    ServerName 361way.com
    ServerAdmin squire@361way.com
    DocumentRoot /srv/www.361way.com/public_html

    PythonPath "['/srv/www.361way.com/application'] + sys.path"
    <Location "/">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE settings
        PythonDebug Off
    </Location>

    ErrorLog /srv/www.361way.com/logs/error.log
    CustomLog /srv/www.361way.com/logs/access.log combined
</VirtualHost>
网站静态目录设置:
<Location "/files/">
    SetHandler None
</Location>
同一主机上多django程序应用,虚拟主机配置文件配置如下:
<Location "/lollipop">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE lollipop.site.settings
    PythonDebug Off
    PythonInterpreter lollipop
</Location>

<Location "/funnyjoke">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE funnyjoke.site.settings
    PythonDebug Off
    PythonInterpreter funnyjoke
</Location>
最后,重启httpd服务,使其生效。




本站的发展离不开您的资助,金额随意,欢迎来赏!

You can donate through PayPal.
My paypal id: itybku@139.com
Paypal page: https://www.paypal.me/361way

分类: http/html/web 标签:
  1. 本文目前尚无任何评论.