web项目部署环境:
Django+Python+Mod_wsgi+Apache
centos python升级见:http://blog.csdn.net/wushanyun1989/article/details/54880251
执行这个安装过程,启动django后会出现报错:
- 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>
另外需要特别注意的是/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