1 查看版本 lsb_release -a
2 查看内核 uname -a 或 cat /proc/version
3 查看位数 uname -m
4安装虚拟环境 sudo pip install virtualenv virtualenvwrapper
5 配置环境 vi .bashrc
#添加virtualenv环境设置
export WORKON_HOME=$HOME/.VENV #环境目录
export PROJECT_HOME=$HOME/PJENV #项目目录
source /usr/local/bin/virtualenvwrapper.sh
6 方法一:virtualenv创建虚拟环境及工程项目(mkproject HelloTest ) (deactivate 退出环境 workon HelloTest 切换环境)
![](https://i-blog.csdnimg.cn/blog_migrate/c3aaf665749d2ee5d638ed460d58aa7e.png)
方法二:指定python版本创建虚拟环境
1先查找python路径(find /usr/bin/ -name python*)
![](https://i-blog.csdnimg.cn/blog_migrate/5674cad6ebc2777f3039c0d363b3def1.png)
2 指定版本创建 mkvirtualenv --python=/usr/bin/python3 mkTest
![](https://i-blog.csdnimg.cn/blog_migrate/e3e60ba577f1f3256837528e104c87bd.png)
7 安装Django模块 pip install django
![](https://i-blog.csdnimg.cn/blog_migrate/785b5106d5e05a3b32b5a72827ff8199.png)
8 创建django项目 django-admin startproject HellTestPro
![](https://i-blog.csdnimg.cn/blog_migrate/87f96266a3820e74e4191149dced174a.png)
9 更改setting设置允许网络访问ALLOWED_HOSTS = ['*']
10 运行Django项目看是否能运行
python manage.py runserver 192.168.1.14:8080
11 配置Apache服务器
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 cd /etc/apache2/ 2 vi apache2.conf 3 加载mod_wsgi.so (安装sudo apt-get install libapache2-mod-wsgi) LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so 153 <Directory /> 154 Options FollowSymLinks 155 AllowOverride None 156 #Require all denied 注释掉不然没权限访问 157 Require all granted 158 </Directory> 4 ht@HT:/etc/apache2/sites-available$ ls 000-default.conf default-ssl.conf HelloWorld.conf test.conf 5 sudo cp HelloWorld.conf HelloWorldPro.conf 6 vi HelloWorldPro.conf Listen 85 WSGIPythonPath /home/ht/.VENV/HelloTest:/home/ht/.VENV/HelloTest/lib/python2.7/site-packages #添加创建虚拟环境的路径 WSGIPythonHome /home/ht/.VENV/HelloTest #添加虚拟环境目录 <VirtualHost 192.168.1.14:85> ServerName 192.168.1.14 ServerAlias 192.168.1.14 ServerAdmin webmaster@localhost WSGIScriptAlias / /home/ht/PJENV/HelloTest/HellTestPro/HellTestPro/wsgi.py #添加Django项目中wsgi.py <Directory /home/ht/PJENV/HelloTest/HellTestPro>#添加Django项目路径 Require all granted </Directory> <Directory /home/ht/PJENV/HelloTest/HellTestPro/HellTestPro> <Files wsgi.py> Require all granted </Files> </Directory> CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 7 创建链接 cd ../sites-enabled/ sudo ln -s ../sites-available/HelloWorldPro.conf HelloWorldPro.conf 8 重启服务器 sudo /etc/init.d/apache2 restart
12 配置Django项目文件 wsgi.py
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
sudo vi wsgi.py import os import sys path = '/home/ht/PJENV/HelloTest'#配置项目路径 if path not in sys.path: sys.path.insert(0, '/home/ht/PJENV/HelloTest/HelloTestPro')#配置到django项目文件 os.environ['DJANGO_SETTINGS_MODULE'] = 'HelloTestPro.settings' from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
13 浏览器运行 http://192.168.1.14:85/
![](https://i-blog.csdnimg.cn/blog_migrate/25f632e464cf80eb02ed72b99f2b61ec.png)
14 错误日志查看
ht@HT:/var/log/apache2$ ls
access.log error.log other_vhosts_access.log