nginx+uwsgi+django+python+ MySQL to build a reliable Python Web server

Source: Internet
Author: User

First, install the necessary tools

Yum-y install gcc gcc-c++ rpm-build mysql* libtool-ltdl* libtool automake autoconf libtool make Setuptool

Second, compile and install python2.7.5

1. Download python2.7.5, save to/data/qtongmon/software

http://www.python.org/ftp/python/

2. Extracting files

Tar xvf python-2.7.5.tar.bz2

3. Create the installation directory

Mkdir/usr/local/python27

4. Install Python

./configure--prefix=/usr/local/python27--enable-shared

Make

Make install

5. Modify the old version of ln direction (note: This change may affect the use of Yum)

mv/usr/bin/python/usr/bin/python2.4.3

Ln-s/usr/local/python27/bin/python/usr/bin/python

6.yum is written in Python, and upgrading a new version of Python will cause Yum to be unavailable, as in the error message when running Yum:

There was a problem importing one of the Python modules

Required to run Yum. The error leading to this problem was:

No module named Yum

Workaround:

Find a Yum file and edit this py file

[email protected] ~]# which Yum

/usr/bin/yum

[Email protected] ~]# Vi/usr/bin/yum

Will

#!/usr/bin/python

Switch

Whereis python out of the results (old version of Python)

#!/usr/bin/python2.6

Then save OK.

Second, installation Uwsgi

Download the latest version of Uwsgi

wget http://projects.unbit.it/downloads/

Because I ended up using XML to configure the Django app deployment, so compiling UWSGI needs to compile the libxml.

Yum-y Install Libxml2-devel

The rest is simple.

Tar zxvf uwsgi-1.9.17.tar.gz

CD uwsgi-1.9.17

Make

CP Uwsgi/usr/sbin/uwsgi

If you encounter an error: Python:error while loading shared libraries:libpython2.7.so.1.0:

Cannot open shared object File:no such file

Resolve as follows:

Vim/etc/ld.so.conf.d/python2.7.conf

Add the following:/usr/local/python27/lib (the Lib directory under the actual Python installation path)

Save to run after exiting:

Ldconfig

Can

At this point Uwsgi even if the installation is complete, the next installation Nginx

for more details, please read on to the next page. Highlights : http://www.linuxidc.com/Linux/2013-10/91063p2.htm

Recommended Reading :

You should use Nginx + Uwsgi http://www.linuxidc.com/Linux/2013-07/87286.htm

UWSGI + Nginx Deployment Flask WEB Application http://www.linuxidc.com/Linux/2013-06/85828.htm

DJANGO+NGINX+UWSGI Deployment Http://www.linuxidc.com/Linux/2013-02/79862.htm

Linux under NGINX+UWSGI deployment Python application http://www.linuxidc.com/Linux/2012-10/72443.htm

Ubuntu Server 12.04 Installation Nginx+uwsgi+django Environment http://www.linuxidc.com/Linux/2012-05/60639.htm

CentOS 5.5 + Nginx 0.8.50 + Uwsgi + Django 1.2.3 Deployment Django Project http://www.linuxidc.com/Linux/2011-05/36399.htm

2nd page (total 2 pages)

Three, Nginx installation

detailed description of Nginx : please click here
Nginx : please click here.

Refer to the CentOS 6.4 installation configuration nginx+pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Note that the compile time to add parameters:--with-cc-opt= '-o3 '--with-cpu-opt=opteron

[Email protected] nginx-1.4.2]#/configure--with-http_stub_status_module--prefix=/usr/local/nginx--with-cc-opt= '-o3 '--with-cpu-opt=opteron

Iv. installation of Mysql-python

wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download

Tar zxvf mysql-python-1.2.3.tar.gz

CD mysql-python-1.2.3

Python setup.py Install

Importerror:no module named Setuptools solution:

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz

Tar zxvf setuptools-0.6c11.tar.gz

CD SETUPTOOLS-0.6C11

Python setup.py Build

Python setup.py Install

/usr/bin/ld:cannot find-lpython2.7 Error, Solution:

Cd/usr/lib

Ln-s/usr/local/python27/lib/libpython2.7.so libpython2.7.so

Ll-a|grep python

lrwxrwxrwx. 1 root root 16:39 libpython2.7.so-/usr/local/python27/lib/libpython2.7.so, OCT 1

Drwxr-xr-x. 3 root root 4096 May 3 15:15 python2.6

Error: Error:command ' gcc ' failed with exit status 1

Processing method:

Yum-y Install Mysql-devel

After the installation is complete, check to see if the following files exist in the Site-packages directory under your Python installation directory, which means the installation is successful.

Linux:mysql_python-1.2.3c1-py2.6-linux-i686.egg

Test method

1) Run command python into Python runtime environment

2) Enter the following Python code to test

Import MySQLdb

Test=mysqldb.connect (db= ' mydb ', host= ' localhost ', user= ' root ', passwd= ' P ')

cur = test.cursor ()

Cur.execute (' show databases; ')

For data in Cur.fetchall ():

Print data

V. Installation of Django

wget https://www.djangoproject.com/m/releases/1.5/Django-1.5.4.tar.gz

Tar xzvf django-1.5.4.tar.gz

CD Django-1.5.4

Python setup.py Install

Test your Django Installation

Enter Python in the terminal, enter Python interactive mode and enter as follows:

>>>import Django

Django. VERSION

The version number is displayed in normal conditions.

Six, nginx Configuration

server {

Listen 80; # # Listen for IPv4; This is default and implied

#listen [::]:80 default Ipv6only=on; # # Listen for IPv6

server_name blog.hysia.com;

Access_log/var/log/nginx/blog.hysia.com-access.log;

Error_log/var/log/nginx/blog.hysia.com-error.log;

Location/{

Uwsgi_pass 127.0.0.1:8630;

Include Uwsgi_params;

}

}

nginx+uwsgi+django+python+ MySQL to build a reliable Python Web server

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.