踩坑无数,算自己的一个总结,可能以后会用上。
步骤大体如下:
1、先得安装python
2、设置虚拟环境。
3、在虚拟环境下安装django
4、安装apache2(目前最新的直接安装的就是2.4.29)
5、安装mod_wsgi
1)首先需要进入到虚拟环境当中。
2)然后需要安装apache-dev和当前版本python-dev
3)然后安装官方指导安装wsgi即可。(目前最新是5.0.2)
这块可以看这篇文章[Ubuntu]Python的Web开发环境之mod_wsgi_ubuntu python mod-wsgi-优快云博客
6、设置apache的虚拟目录
<VirtualHost *:8888>
ServerName 127.0.0.1
WSGIScriptAlias / /path/to/website/wsgi.py
##这里是虚拟环境所在的目录
WSGIDaemonProcess website user=www-data group=www-data python-home=/path/to/website ##这里是网址
WSGIProcessGroup website ##跟上面那个一样就行了
## 这里是wsgi的目录
<Directory /path/to/website/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
7、设置wsgi.py文件(这里是为了解决访问不到module的问题)
import os
import sys
from os.path import abspath, dirname
current_path = dirname(dirname(abspath(__file__)))
sys.path.insert(0, current_path)
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")
application = get_wsgi_application()