Nginx + uWSGI + Django + Python environment installation configuration details

Source: Internet
Author: User
Tags character set create database install django pip install django

1. Install PYTHON2.7.7:

[Root @ hz tools] # pwd
/Byrd/tools
[Root @ hz tools] # wget https://www.python.org/ftp/python/2.7.7/Python-2.7.7.tgz
[Root @ hz tools] # tar zxf Python-2.7.7.tgz
[Root @ hz tools] # cd Python-2.7.7
[Root @ hz Python-2.7.7] #./configure -- prefix =/byrd/server/Python-2.7.7
[Root @ hz Python-2.7.7] # make & make install
[Root @ hz Python-2.7.7] # mv/usr/bin/python/usr/bin/python_2.6.6
[Root @ hz Python-2.7.7] # ln-s/byrd/server/Python-2.7.7/bin/python2.7/usr/bin/python
######################################## ################################
Note: vim/usr/bin/yum # Replace! /Usr/bin/python changed! /Usr/bin/python2.6.
######################################## ################################

II. Install uWSGI:

Method 1: pip

[Root @ hz tools] # wget https://bootstrap.pypa.io/get-pip.py
[Root @ hz tools] # python get-pip.py
[Root @ hz tools] # sed-I "s # PATH = \ $ PATH: \ $ HOME \/bin: \/byrd \/server \/Python-2.7.7 \/bin # g "~ /. Bash_profile
[Root @ hz tools] # source ~ /. Bash_profile
[Root @ hz tools] # pip install uwsgi

Method 2: compile and install

[Root @ hz tools] # wget https://pypi.python.org/packages/source/s/setuptools/setuptools-5.2.tar.gz
[Root @ hzsetuptools-5.2] # python setup. py build
[Root @ hzsetuptools-5.2] # python setup. py install
[Root @ hz tools] # wget http://projects.unbit.it/downloads/uwsgi-2.0.5.tar.gz # setuptools must be installed to install uwsgi
[Root @ hz tools] # tar zxf uwsgi-2.0.5.tar.gz
[Root @ hz tools] # cd uwsgi-2.0.5
[Root @ hzuwsgi-2.0.5] # python setup. py build
[Root @ hz uwsgi-2.0.5] # python setup. py install # make can also
Copying uWSGI. egg-info to/byrd/server/Python-2.7.7/lib/python2.7/site-packages/uWSGI-2.0.5-py2.7.egg-info
Running install_scripts
[Root @ hz uwsgi-2.0.5] # make
[Root @ hz uwsgi-2.0.5] # cp uwsgi/usr/bin
[Root @ hz uwsgi-2.0.5] # chmod + x/usr/bin/uwsgi

3. Install Django:

Others:

[Root @ hz tools] # wget https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
[Root @ hz tools] # unzip MySQL-python-1.2.5.zip
[Root @ hz tools] # cd MySQL-python-1.2.5
[Root @ hz MySQL-python-1.2.5] # sed-I's # mysql_config =/usr/local/bin/mysql_config # mysql_config =/usr/local/mysql/bin/mysql_config # g 'site. cfg # Change to/usr/local/mysql/bin/mysql_config
[Root @ hzMySQL-python-1.2.5] # python setup. py build
[Root @ hzMySQL-python-1.2.5] # python setup. py install
Method 1:

[Root @ hz tools] # pip install Django = 1.6.5

Method 2:

[Root @ hz tools] # wget https://www.djangoproject.com/m/releases/1.6/Django-1.6.5.tar.gz
[Root @ hz tools] # tar zxf Django-1.6.5.tar.gz
[Root @ hz tools] # cd Django-1.6.5
[Root @ hzDjango-1.6.5] # python setup. py build
[Root @ hzDjango-1.6.5] # python setup. py install

4. Create a project

[Root @ hz tools] # cd/web/site/
[Root @ hz site] # sed-I's # \ $ HOME/bin:/byrd/tools/Django-1.6.8/django/bin # G '~ /. Bash_profile
[Root @ hz site] # source ~ /. Bash_profile
[Root @ hz site] # django-admin.py startproject Byrd
[Root @ hz site] # cd Byrd/
[Root @ hz Byrd] #/usr/local/mysql/bin/mysql-uroot-p
Mysql> create database django default character set utf8 collate utf8_general_ci;
Mysql> create user 'Django '@ 'localhost' identified by 'admin ';
Mysql> grant all on django. * to 'Django '@ 'localhost' identified by 'admin ';
Mysql> flush privileges;
[Root @ hz Byrd] # vim Byrd/settings. py
#### Modify line 8-63 ####
DATABASES = {
'Default ':{
'Engine': 'Django. db. backends. Mysql ',
'Name': 'Django ',
'User': 'Django ',
'Password': 'admin ',
'Host': '2017. 0.0.1 ',
'Port': '123 ',
    }
}
#### Modify line 8-63 ####
[Root @ hz Byrd] # python manage. py runserver 0.0.0.0: 8080 # It worked! Proves that django is configured successfully.

V. Django + uWSGI:

[Root @ hz ~] # Cat/usr/local/nginx/conf/uwsgi. ini
[Uwsgi]
Socket = 127.0.0.1: 9001
Chdir =/web/site/Byrd
Pythonpath = ..
Env = DJANGO_SETTINGS_MODULE = Byrd. settings
Module = django. core. handlers. wsgi: WSGIHandler ()
Processes = 4
Threads = 2
Stats = 127.0.0.1: 9191

VI. Nginx:

Server {
Listen 80;
Server_name localhost;
Location /{
Root/web/site/Byrd;
Include uwsgi_params;
Uwsgi_pass 127.0.0.1: 9001;
# Uwsgi_param UWSGI_CHDIR /;
# Uwsgi_param UWSGI_SCRIPT /;
Index. py index.htm;
        }
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
        }
}

7. Boot

[Root @ hz conf] # echo "uwsgi/usr/local/nginx/conf/uwsgi. ini>/dev/null 2> & 1 & ">/etc/rc. local

8. uWSGI startup script:

#! /Bin/bash
# Uwsgi script
# It is v.0.0.1 version.
# Chkconfig:-89 19
# Description: uwsgi script
# Processname: uwsgi
PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Bin
Export PATH
     
Uwsgi_config =/usr/local/nginx/conf/uwsgi. ini
Uwsgi_pn = 'PS aux | grep-v "grep" | grep-c "uwsgi "'
Uwsgi_pid = 'PS-eo pid, comm | grep uwsgi | sed-n 1p | awk '{print $1 }''
Uwsgi_PID =/usr/local/nginx/logs/uwsgi. pid
Uwsgi =/usr/bin/uwsgi
RETVAL = 0
Prog = "uwsgi"
# Source function library.
./Etc/rc. d/init. d/functions
     
     
If [$ (id-u )! = "0"]; then
Printf "Error: You must be root to run this script! \ N"
Exit 1
Fi
     
     
# Start nginx daemons functions.
Start (){
If [$ uwsgi_pn-gt 5]; then
Action "uwsgi is running! "/Bin/true
Exit 0
Fi
Daemon $ uwsgi-x $ {uwsgi_config}
Action "uwsgi start..."/bin/true
}
# Stop nginx daemons functions.
Stop (){
If [$ uwsgi_pn-gt 5]
Then
Kill-9 'PS-eo pid, comm | grep uwsgi | sed-n 1p | awk '{print $1 }''
RETVAL =$?
Action "uwsgi stopping..."/bin/true
Else
Action "uwsgi not running! "/Bin/false
Fi
}
     
# See how we were called.
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Reload)
Reload
;;
Restart)
Stop
Start
;;
*)
Echo $ "Usage: $ prog {start | stop | restart }"
Exit 1
Esac
Exit $ RETVAL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.