centos7.2 PIP3 + python3.5 + Django + nginx + Uwsgi

Source: Internet
Author: User
Tags virtual environment virtualenv install redis

Centos7.2 installing Python 3.5 and PIP installation

NOTICE: 1. CentOS comes with python2.7

2. This tutorial is suitable for most Linux systems, this article takes centos7.2 as an example

Installing Python 3.51.centos7.2 Install Python's dependency package

Yum Groupinstall "Development tools"
Yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel Libpcap-devel Xz-devel

2, download the Python3.5 source package and compile

wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
Tar XF python-3.5.0.tgz
CD Python-3.5.0
./configure--prefix=/usr/local--enable-shared
Make
Make install

# Create Python3 Soft Links
Ln–s/usr/local/bin/python3/usr/bin/python3

3. You need to configure the library before running Python:

Echo/usr/local/lib >>/etc/ld.so.conf.d/local.conf
Ldconfig

4. Operation:

Python3--version
Python 3.5.0

Python 3.5.0 installed successfully!

How to install Easy_install, pip 1.CentOS Install Easy_install method:

Wget-q http://peak.telecommunity.com/dist/ez_setup.py
Python ez_setup.py

2., CentOS install Python package Management Installation Tool Pip method is as follows:

wget--no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz

Tar zvxf 1.5.5

CD pip-1.5.5/

Python3 setup.py Install

OK, so it's ready to install PIP.

Building a virtual Environment 1. Install the virtual environment

sudo pip install virtualenv

  1. Installing the Virtual Environment Expansion pack

    Pip Install Virtualenvwrapper

  2. sudo modifies the home directory under configuration files. BASHRC:

    CD # Home Directory

    VI. BASHRC #打开文件, add the following:

    Export Workon_home= $HOME/.virtualenvs

    source/usr/local/bin/virtualenvwrapper.sh

  3. Use the source. BASHRC command to make the configuration file effective.

    source. BASHRC

  4. To create a PYTHON3 virtual environment:

    Mkvirtualenv-p Python3 Py_django

  5. Enter the virtual environment you created, install the corresponding project all the packages that need to be installed

    Workon Py_django

    Pip install ...

    Install Redis, MySQL data set library, and start (use to Redis in this project)

    Install UWSGI1, enter virtual environment installation UWSGI

    Pip Install Uwsgi

    2. Configure Uwsgi, create the Uwsgi.ini file under the project directory, configured as follows:

    [Uwsgi]

    #使用nginx连接时使用

    socket=127.0.0.1:8092

    #直接做web服务器使用

    # http=127.0.0.1:8092

    #项目目录地址

    Chdir=/srv/http/dailyfresh

    #项目中wsgi the directory of the. py file, relative to the project directory

    wsgi-file=dailyfresh/wsgi.py

    Processes=4

    threads=2

    Master=true

    Pidfile=uwsgi.pid

    Daemonize=uwsgi.log

    # Virtual Environment Address

    Virtualenv=/root/.virtualenvs/py_django

  6. 启动uwsgi

    Uwsgi--ini Uwsgi.ini

    FTP Upload Code

    Place the code under the SRV file in the root directory and not in the root directory

    Install Nginx execute the following command to install

    cd/usr/local/

    wget http://nginx.org/download/nginx-1.5.6.tar.gz Tar XF nginx-1.5.6.tar.gz

    CD nginx-1.5.6

    ./configure

    Make && make install

    Now the User/local directory has a more Nginx file

    Modifying the nginx.conf configuration

    VI usr/local/nginx/conf/nginx.conf

    Start Nginx

    Nginx/sbin/nginx

    Access public IP with a browser

    You can display the HTML file of the Web page.

    Static file display

    Create the following directory on the server.

    sudo mkdir-vp/var/www/dailyfresh/static/

    Modify directory permissions.

    sudo chmod 777 /var/www/dailyfresh/static/

    修改dailyfresh/settings.py文件。
    STATIC_ROOT=‘/var/www/dailyfresh/static/‘

    收集所有静态文件到static_root指定目录。
    python manage.py collectstatic

    Stop and then start the Nginx service.

    Personal CentOS deployment, some different, please friends to modify their own

centos7.2 PIP3 + python3.5 + Django + nginx + Uwsgi

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.