Django(1.7.11)+Python(2.7.11) centos部署

web项目部署环境:

Django+Python+Mod_wsgi+Apache

centos python升级见:http://blog.csdn.net/wushanyun1989/article/details/54880251

执行这个安装过程,启动django后会出现报错:

  1. django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3  


解决方法:需要单独安装sqlite,然后重新编译python


apache安装见:http://blog.csdn.net/wushanyun1989/article/details/54882161


Django安装:

下载地址:https://www.djangoproject.com/

Django安装相对较简单

tar -zxvf Django-1.7.11.tar.gz
cd Django-1.7.11
python setup.py install

安装Mod_wsgi

因为Apache没有自带wsgi模块,所以如果用wsgi启动Django服务,需要自己安装mod_wsgi模块供apache使用

下载地址:https://pypi.python.org/pypi/mod_wsgi/4.4.5

tar-zxvf mod_wsgi-4.4.5.tar.gz
cd mod_wsgi-4.4.5
./configure --with-apxs=/usr/local/apache/bin/apxs --with-python=/usr/local/bin/python
make && make install

配置Apache

简单配置一下apache服务,即可加载Django应用,在apache/conf目录下修改httpd.conf配置文件,在LoadModule最后加上

LoadModule wsgi_module modules/mod_wsgi.so

同时去掉多余的<Directory></Directory>匿名块,如果只有一个应用,只需做如下配置即可:

WSGIScriptAlias / /data/riskview/demo/demo/wsgi.py
WSGIPythonPath /data/riskview/demo
Alias /static /data/riskview/demo/static/


<Directory /data/riskview/demo/demo>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

/data/riskview/demo
是一个简单的web项目,创建方法见下文。

另外需要特别注意的是/static目录也需要做一下Alias,否则CSS、JS以及图片等资源文件可能无法正常加载。

完成配置后重启一下apache服务,Django服务即可正常使用:

500错误码的解决:RuntimeError: populate() isn't reentrant mod_wsgi (pid=26842): Exception occurred processing WSGI script '/data/riskview/demo/demo/wsgi.py'.

出现这个错误的原因主要是由于频繁修改py代码造成的,解决方法:重启apache服务!更多详细的解决办法见链接:

http://stackoverflow.com/questions/27093746/django-stops-working-with-runtimeerror-populate-isnt-reentrant

django unable to open database file错误的解决:

http://stackoverflow.com/questions/21054245/attempt-to-write-a-readonly-database-django-w-selinux-error

what is Centos 5's apache user/group [closed]

http://serverfault.com/questions/416236/what-is-centos-5s-apache-user-group

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值