apache下安装python模块运行django站点框架
安装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虚拟主机;
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonDebug Off
如果你想你的Django应用程序存储在另一个位置,需要给其指定一个路径在上面的配置中
PythonPath “[‘/srv/www/brackley.net/application’] + sys.path”
如下,是一个站点为361way.com站点的配置文件
ServerName 361way.com
ServerAdmin [email protected]
DocumentRoot /srv/www.361way.com/public_html
PythonPath “[‘/srv/www.361way.com/application’] + sys.path”
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonDebug Off
ErrorLog /srv/www.361way.com/logs/error.log
CustomLog /srv/www.361way.com/logs/access.log combined
网站静态目录设置:
SetHandler None
同一主机上多django程序应用,虚拟主机配置文件配置如下:
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE lollipop.site.settings
PythonDebug Off
PythonInterpreter lollipop
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE funnyjoke.site.settings
PythonDebug Off
PythonInterpreter funnyjoke
最后,重启httpd服务,使其生效。
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/django/634.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.