Centos6.5+django+mysql+nginx+uwsgi

Source: Internet
Author: User
Tags openssl install django iptables pip install django

1, installation of Nginx. The nginx-1.6.0 is used here to create a shell script and execute it.

#!/bin/bashnginx_version= "nginx-1.6.0" yum-y install gcc gcc-c++ pcre pcre-devel OpenSSL openssl-develcd softtar zxvf $ng Inx_version ". tar.gz" CD $nginx _version./configure   --error-log-path=/var/log/nginx/error.log--http-log-path=/ Var/log/nginx/access.log--with-http_stub_status_module--with-http_ssl_modulemakemake installcp/usr/local/nginx/ Conf/nginx.conf/usr/local/nginx/conf/nginx.conf.bak/usr/local/nginx/sbin/nginx  -c/usr/local/nginx/conf/ Nginx.confecho "/usr/local/nginx/sbin/nginx" >>/ETC/RC.LOCALCD. RM-RF $nginx _version
Here is the setting of the Iptables
Iptables-fiptables-a input-m State--state new-m tcp-p TCP--dport 3306-j acceptiptables-a input-p tcp-m TCP--DP ORT 80-j acceptiptables-a input-p tcp-m tcp--dport 22-j acceptiptables-a input-i lo-j acceptiptables-a input-m State--state related,established-j acceptiptables-p INPUT dropservice iptables Save
2.mysql installation, where MySQL is using 5.6.14, create a new shell script to paste the following text

#!/bin/bashmysql_version= "mysql-5.6.14" yum-y install vim libevent* libtool* autoconf* libstd* ncurse* bison* OPENSSL*CD Softtar zxvf cmake-2.8.12.1.tar.gzcd cmake-2.8.12.1./configure && make && make INSTALLCD. RM-RF Cmake-2.8.12.1tar zxvf $mysql _version ". tar.gz" CD $mysql _versioncmake-dcmake_install_prefix=/usr/local/mysql- Dmysql_datadir=/usr/local/mysql/data-dsysconfdir=/etc-dwith_myisam_storage_engine=1-dwith_innobase_storage_ Engine=1-dwith_memory_storage_engine=1-dwith_readline=1-dmysql_unix_addr=/var/lib/mysql/mysql.sock-dmysql_tcp_ Port=3306-denabled_local_infile=1-dwith_partition_storage_engine=1-dextra_charsets=all-ddefault_charset=utf8- Ddefault_collation=utf8_general_cimake && make Installgroupadd mysqluseradd-g mysql mysqlchown-r mysql:mysql/ usr/local/mysqlcd/usr/local/mysqlscripts/mysql_install_db--basedir=/usr/local/mysql--datadir=/usr/local/mysql/ Data--user=mysql--LDATA=/VAR/LIB/MYSQLCP support-files/mysql.server/etc/init.d/Mysqlchkconfig MySQL onchmod 755/etc/init.d/mysqlservice mysql startecho "path=/usr/local/mysql/bin: $PATH" >>/ Etc/profileecho "Export PATH" >>/etc/profilesource/etc/profilemysqladmin-u root password 123456cd-cd. RM-RF $mysql _version


3. Start installing Django, which is using the latest Django stable version of 1.6.5

Install the necessary packages

Yum Groupinstall "Development tools" Yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel Sqlite-devel readline-devel tk-devel python-devel libxml2  libxml2-devel  python-setuptools  zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake

install pip software
wget http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz--no-check-certificate  tar xvfz pip-1.0.2.tar.gz   cd pip-1.0.2  python setup.py  Install
Pip--version  See if PIP is installed
Installing UWSGI
Pip Install Uwsgiuwsgi--version


Create a new web.py file with the following contents:

DEF application (env, start_response):    start_response (' OK ', [(' Content-type ', ' text/html ')]    return " Hello World "

Then run at the terminal:
Uwsgi--http:8001--wsgi-file test.py
Enter in the browser: http://127.0.0.1:8001 to see if there is "Hello world" output.

Installing Django

Pip Install Django

django-admin.py Startproject DEMOSITECD Demosite
Python manage.py runserver 0.0.0.0:8002
Enter: http://127.0.0.1:8002 in the browser to check if Django is working properly.


Configure Uwsgi

To create a new Uwsgi9090.ini in the/ect/directory, add the following configuration:

[Uwsgi]socket = 127.0.0.1:9090master = True         //main Process Vhost = TRUE//          multi-station mode workers = 2           //number of sub-processes Reload-mercy =     Vacuum = True         //exit, clean file on restart max-requests =   Limit-as = 512buffer-sizi = 30000pidfile =/var/run/uwsgi9090.pid< C6/>//pid file for the following script to start, stop the process daemonize =/website/uwsgi9090.log

Set Uwsgi boot up, create a new uwsgi9090 file in the/ect/init.d/directory with the following contents:

#! /bin/sh# chkconfig:2345 25# description:startup script for Uwsgi webserver on Debian. Place in/etc/init.d and# Run ' update-rc.d-f uwsgi defaults ', or with the appropriate command on your# distro. For Centos/redhat run: ' Chkconfig--add Uwsgi ' # # # BEGIN INIT info# provides:uwsgi# required-start: $all # Req Uired-stop: $all # default-start:2 3 4 * default-stop:0 1 6# short-description:starts the UWSGI Web server # description:starts Uwsgi using start-stop-daemon### END INIT INFO # author:licess# website:http://lnmp.org P ath=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bindesc= "Uwsgi Daemon" name=uwsgi9090daemon=/usr/ bin/uwsgiconfigfile=/etc/$NAME. inipidfile=/var/run/$NAME. pidscriptname=/etc/init.d/$NAME set-e[-X "$DAEMON" | | Exit 0 Do_start () {$DAEMON $CONFIGFILE | | echo-n "UWSGI already Running"} do_stop () {$DAEMON--stop $PIDFILE | | e Cho-n "Uwsgi not Running" Rm-f $PIDFILE echo "$DAEMON stoped."} Do_reload () {$DAEMON--reload $PIDFILE | | echo-n "UWSGI can ' t reload"} do_status () {PS Aux|grep $DAEMON} case "$" in status ) Echo-en "Status $NAME: \ n" do_status;; Start) Echo-en "starting $NAME: \ n" Do_start;; Stop) Echo-en "stopping $NAME: \ n" do_stop;; reload|graceful) Echo-en "reloading $NAME: \ n" do_reload; *) echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2 exit 3;; ESAC Exit 0
Set Uwsgi boot up
Chkconfig--add uwsgi9090 chkconfig uwsgi9090 on

Modify the Nginx conf file

server {        listen       ;        server_name  localhost;                Location/{                        include  uwsgi_params;            Uwsgi_pass  127.0.0.1:9090;              Must be consistent with the settings in Uwsgi            uwsgi_param uwsgi_script Demosite.wsgi;  The portal file, the location of the wsgi.py relative to the project root directory, "." Equivalent to a level of directory            Uwsgi_param Uwsgi_chdir/demosite;       Project root directory            index  index.html index.htm;            Client_max_body_size 35m;        }    }
Service uwsgi9090 Start
in the browser input: http://127.0.0.1, congratulations you can see Django's "It work" ~

Installing Mysql-python

Pip Install Mysql-python

Test the connectivity of Django to MySQL
Run the Python manage.py Shell in the project and

From django.db import connectioncursor=connection.cursor ()









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.