UbuntuServer12.04 install Nginx + uWSGI + Django Environment

Source: Internet
Author: User
Today we want to introduce the use of APT source direct apt-getinstall installation configuration we need environment, first install MySQL and Nginx according to the Convention first: linuxidc@www.linuxidc.com :~ $ Sudosu-root@www.linuxidc.com :~ $ Apt-getinstallmysql-serverroot@www.linuxidc.com :~ $

Today, we will introduce how to directly install and configure the environment we need using APT source apt-get install. First, install MySQL and Nginx as usual:

  1. Linuxidc @ www.linuxidc.com:~$Sudo su-
  2. Root @ www.linuxidc.com:~$Apt-Get install mysql-Server
  3. Root @ www.linuxidc.com:~$Apt-Get install nginx
Then we can find the required uWSGI in sid through the Debian Packages website. To use the software package in sid, we also need to modify our/etc/apt/sources. list source, add the deb http://ftp.tw.debian.org/debian sid main non-free contrib line, or directly enter the command:
  1. Root @ www.linuxidc.com:~$Echo "deb http://ftp.tw.debian.org/debian sid main non-free contrib">/etc/apt/sources. list
After configuring the source list, we can install it using the following command:
  1. Root @ www.linuxidc.com:~$Apt-Get update
  2. Root @ www.linuxidc.com:~$Apt-Get install uwsgi-Core uwsgi-Plugin-Python


After the installation is complete, the configuration file is put in the/etc/uwsgi by convention, service control can be achieved through the invoke-rc.d uwsgi followed by command parameters, but here there is an episode I have to mention, the following error may be reported during installation:

The following packages have unmet dependencies:
Libc6-dev: Breaks: gcc-4.4 (<4.4.6-4) but 4.4.5-8 is to be installed.
E: Broken packages
It seems that the gcc version of the dependent package does not match. I solved it in the following way:

 

  1. Root @ www.linuxidc.com:~$Apt-Get update
  2. Root @ www.linuxidc.com:~$Apt-Get upgrade # first try to upgrade the system software package
  3. Root @ www.linuxidc.com:~$Apt-Get install libc6-Dev
Next, install MySQL support for django and Python and continue the APT command:

 

  1. Root@ Notebook:~$Apt-Get install python-Django python-Mysqldb
View the python version of the application.
  1. Root@ Notebook:/Usr/Lib $ python--Version
As you know, django is installed under site-packages in the python directory, but none of these python directories have the site-packages folder, in fact, we can use the following command to locate the problem:

 

  1. Root@ Notebook:/Usr/Lib $ python-C"From distutils. sysconfig import get_python_lib; print get_python_lib ()"
The above command prints the Python package path on the console. For example, here we may obtain the dist-packages directory. Switch to this directory and you will find django there. Add permissions to the django-admin.py, and then make a symbolic connection so that we can operate later (I am here Django under Python2.7 ):
  1. Root@ Notebook:/Usr/Lib $ chmod 777/Usr/Lib/Python2.7/Dist-Packages/Django/Bin/Django-Admin.Py
Now, the installation section is basically complete. The configuration section is explained below. First, create a folder for our project, for example, put it under/opt/www, run the following command to create a Django project named mysite:
  1. Root@ Notebook:~$Cd/Opt/Www
  2. Root@ Notebook:/Opt/Www $ django-Admin.Py startproject mysite
Now, the/opt/www directory should have a sub-folder named mysite. We need to drop a wsgi configuration file to/opt/www/mysite, the configuration file is named wsgi. py, the content is as follows:
  1. # Wsgi.Py
  2. #/Opt/Www/Mysite/Wsgi.Py
  3. ImportSys
  4. ImportOS
  5.  
  6. Sys.Path.Append(OS.Path.Abspath(OS.Path.Dirname(_ File __)))
  7. # The following line shows the parent directory of mysite.
  8. Sys.Path.Append('/Opt/www')
  9. # Change the values in the following line to the corresponding project name..Settings
  10. # Here Is mysite.Settings
  11. OS.Environ['Django _ SETTINGS_MODULE'] = 'Mysite. settings'
  12.  
  13. ImportDjango.Core.Handlers.Wsgi
  14.  
  15. Application=Django.Core.Handlers.Wsgi.WSGIHandler()

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.