Project environment:
centos7 、
apache2、
django2.0
python3.7
I originally wanted to test the deployment of the project using apache. After reading a good tutorial on the Internet, I started to do it with confidence, but my face really hurts. After the deployment is completed, there are missing packages, and the error description is: No module named site . Generally speaking, seeing this type of error is the wrong version of mod_wsgi installed.
**Solution
Do not use yum install mod_wsgi to install, because python2.7 will be automatically installed and selected. The official document points out the precautions for virtual environment installation https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html . Here we use the ius source installation,
First install the ius source:
$ curl https://setup.ius.io/ | bash
Different python versions of mod_wsgi are included in the ius source:
$ 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
I am using python3.6 and install python36u-mod_wsgi directly. If the version you are using is not available in ius, then consider compiling and installing mod_wsgi yourself .
yum erase mod_wsgi # 卸载之前安装的mod_wsgi
yum install -y python36u-mod_wsgi
After the installation is complete, the file /etc/httpd/conf.modules.d/10-wsgi-python3.6.conf will be generated, which is the configuration file of the newly installed apache module.
There are many great gods who wrote other configurations online very well, so I won't add more.
Reference blog:
https://www.lijiaocn.com/prog/django/deploy_apache.html
https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
https://zhuanlan.zhihu.com/p/35080834
http://www.showerlee.com/archives/2511