项目环境:
centos7、
apache2、
django2.0、
python3.7
本来想测试一下使用apache部署项目,在网上看了很好教程就信心满满的开始动手,但是脸真疼。部署完成之后就是缺包少件,错误描述:No module named site。一般来说看到这种类型错误就是mod_wsgi安装版本错误。
**解决方法
不要使用yum install mod_wsgi的方式安装,因为会自动安装选择python2.7,官方文档指出虚拟环境安装的注意事项https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html。这里我们使用用ius源安装,
首先安装ius源:
$ curl https://setup.ius.io/ | bash
ius源中包含了不同python版本的mod_wsgi:
扫描二维码关注公众号,回复:
13750490 查看本文章
![](/qrcode.jpg)
$ yum search mod_wsgi
python35u-mod_wsgi-debuginfo.x86_64 : Debug information for package python35u-mod_wsgi
python36u-mod_wsgi-debuginfo.x86_64 : Debug information for package python36u-mod_wsgi
koschei-frontend.noarch : Web frontend for koschei using mod_wsgi
mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python35u-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python36u-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
viewvc-httpd-wsgi.noarch : ViewVC configuration for Apache/mod_wsgi
我使用的是python3.6,直接安装python36u-mod_wsgi,如果ius里也没有你用的版本,那么就考虑自己编译安装mod_wsgi。
yum erase mod_wsgi # 卸载之前安装的mod_wsgi
yum install -y python36u-mod_wsgi
安装完成之后会生成文件 /etc/httpd/conf.modules.d/10-wsgi-python3.6.conf,这个就是新安装的apache模块的配置文件。
其他的配置网上有很多大神写的很好,我就不画蛇添足了。
参考博客:
https://www.lijiaocn.com/prog/django/deploy_apache.html
https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html