ubuntu18.04上搭建django项目测试环境

今天来聊一下django项目测试环境的搭建,看下面的具体步骤。python

如下环境在ubuntu18.04下搭建,步骤以下:mysql

1.安装数据库mysql5.7:
1)安装git

sudo apt-get install mysql-server
sudo apt-get install mysql-client

设置root用户的密码:github

1)进入mysql: mysql
2)select user, plugin from mysql.user;
3)设置root密码: update mysql.user set authentication_string=PASSWORD('test'),                              plugin='mysql_native_password'     where user='root';
4)刷新使设置生效: flash privileges;
5)退出从新登录: mysql -uroot -ptest 便可

2.安装redis:redis

sudo apt-get install redis-server

3.安装git:sql

sudo apt-get install git

生成公钥:
执行ssh-keygen后,会将公钥和私钥保存在当前用户目录下的.ssh文件夹中,id_rsa.pub就是须要配置到码云、github等的公钥。数据库

4.安装python3.6:
个人ubuntu18.04中自带python3.6.5, 因此不用安装,输入python3便可进入django

5.安装virtualenv和virtualenvwrapper:
1)安装pip3ubuntu

sudo apt install python3-pip

2)安装virtualenv和virtualenvwrapperbash

sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper

3)配置virtualenvwrapper:
建立存放虚拟环境的目录:

mkdir virtualenvs

2)修改.bashrc文件,增长下面几行:

export WORKON_HOME=$HOME/virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

3)使修改生效:

source .bashrc

virtualenvwrapper经常使用命令以下:

mkvirtualenv [-p /usr/bin/python3.6 ] test: 建立虚拟环境([]中指定使用的python版本)
workon [test]: 查看有哪些虚拟环境[使用某个虚拟环境]
deactivate: 退出当前虚拟环境
rmvirtualenv test: 删除虚拟环境

6.安装gunicorn(一个wsgi服务器,相似于uwsgi):

sudo pip install gunicorn

使用gunicorn启动django项目:

gunicorn 项目名.wsgi:application --bind 192.168.0.109:8000

7.将gunicorn配置到supervisor中(与systemctl相似,一个进程管理工具)未完待续....

相关文章
相关标签/搜索