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

先设置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/default.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安装项目需要的包
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值