虚拟环境
- 安装virtualenv
- 创建指定python版本的虚拟环境
1
| virtualenv xxx --python=pythonx.x.x
|
- 进入虚拟环境
- 退出虚拟环境
- 删除虚拟环境
Django
- Django安装
- 创建django项目
1
| django-admin startproject HelloWorld
|
- 运行django项目
1
| python manage.py runserver 0.0.0.0:8000
|
Apache
- 安装apache
1
| sudo apt install apache2
|
- 安装mod_wsgi模块
1
| sudo apt install libapache2-mod-wsgi-py3
|
- 查看apache运行状态:
1
| systemctl status apache2
|
- 复制一份新的配置文件
1
| sudo cp 000-default.conf mysite.conf
|
- 写入下列信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <VirtualHost *:8000> WSGIScriptAlias / /home/django/mysite/mysite/wsgi.py <Directory /home/django/mysite/mysite> <Files wsgi.py> Require all granted </Files> </Directory> Alias /static/ /home/django/mysite/static/ <Directory /home/django/mysite/static> Require all granted </Directory>
Alias /media/ /home/django/mysite/media/ <Directory /home/django/mysite/media> Require all granted </Directory>
WSGIDaemonProcess mysite python-home=/home/django/django-env python-path=/home/django/mysite WSGIProcessGroup mysite </VirtualHost>
|
- 修改端口号,打开
/etc/apache2/ports.conf
,修改Listen 80
- 重启apache
1 2 3 4
| a2ensite mysite.conf //激活 a2dissite 000-default.conf //关闭自身站点 apache2ctl configtest //检查配置有无问题,有的话自行解决 apache2ctl restart
|
参考
[1] Ubuntu+Apache+Django部署