您的位置:首页 > 数据库 > MariaDB

Centos7&Python2.7&django&uwsgi&mariadb&python虚拟环境

2017-10-16 17:49 483 查看
先设置Python 环境变量 否则容易出错

1.安装、升级pip

先安装epel源

yum -y install epel-release
yum -y install python-pip
pip install --upgrade pip


2.安装配置django

pip install django


3.安装mysql、uwsgi

yum -y install mariadb mariadb-server
yum -y install MySQL-python mariadb-devel

**yum -y install python-devel #不安装此包 uwsgi会报错**
pip  isntall uwsgi
#测试uwsgi
touch test.py
1 # test.py
2 def application(env, start_response):
3      start_response('200 OK', [('Content-Type','text/html')])
4      return "Hello World"

uwsgi --http :8080 --chdir /home/mysite -w mysite.wsgi
#测试wsgi是否正常运行


django-admin startproject mytest
uwsgi --http :80 --chdir /home/mytest --module mytest.wsgi
#测试django


wsgi配置文件

在/etc/下建立uwsgi8008.ini文件

1 [uwsgi]
2 #socket=/home/qian/django.sock
3 socket=192.168.37.128:8889
4 chdir =/home/qian/qian
5 wsgi-file=qian/wsgi.py
6 processes=4
7 threads=2
8 stats=192.168.37.128:9191


nginx配置文件

/etc/nginx/de
4000
fault.d/8008.conf

#mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 192.168.37.128:8889; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
# the port your site will be served on
listen      80;
# the domain name it will serve for
server_name 192.168.37.128; # substitute your machine's IP address or FQDN
charset     utf-8;

# max upload size
client_max_body_size 75M;   # adjust to taste

# Django media
location /media  {
alias /home/qian/media;  # your Django project's media files - amend as required
}

location /static {
alias /home/qian/static; # your Django project's static files - amend as required
}

# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass  django;
include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
}
}


python虚拟环境

Virtualenv

安装epel扩展源

yum install epel-release

安装pip

yum install python-pip

安装virtualenv和virtualenvwrapper

pip install virtualenv virtualenvwrapper

编辑~/.bashrc文件,结尾添加以下内容

export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh

然后执行以下命令使配置生效

source ~/.bashrc

创建env

mkvirtualenv explame

使用pip安装项目需要的包
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: