One click site building guide of native Tencent cloud centos7.5 Django Nginx+uwsgi

Keywords: Python Django yum Nginx

First, you need to have a server and domain

Preprocessing

Install GCC, ZLIB, PCRE, OPENSSL...

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

Pyhton's upgrade and iteration

Native linux generally only provides Python 2.7, so the first step is to upgrade Python and use the latest and stable version. (it is recognized that the installation directory is / usr/local, user root)

#Pre preparation
yum install sqlite-devel #Install sqlite3
yum install libffi-devel  #Install libffi devel (3 and above)
yum install readline-devel #Allows special symbols on the input keyboard, including direction keys, to be used at the command line
mkdir /usr/local/python3
cd /usr/local/python3
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
tar zxvf Python-3.7.2.tar
cd Python-3.7.2
#Specify installation directory
./configure --prefix=/usr/local/python3
make & make install
#In the process of making, you can see that python is still missing some packages. If you don't need them, don't worry

Create Python 3 shortcut instruction

cd /usr/bin
#Back up the original connection
mv python python.bak
ln -s /usr/local/python3/bin/python3 /usr/bin/python
#Confirm availability
python -V
> Python 3.7.2
#Fix the software problem based on python2
#yum and libexec are currently involved
#Fix the first line of the catalog file#!/usr/bin/python => #!/usr/bin/python2.7
vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down

Install PIP3

How can pip not be used as a package management tool of python?

Native python has its own pip tool, usually pip2. Here we just want to use the new one! Not happy!

#Actually, python3 comes with pip3
cd /usr/local/python3.7.2/bin
#You can see pip3, and also establish the connection
ln -s /usr/local/python3.7.2/bin/pip3 /usr/bin/pip3

Install Django & uwsgi

pip3 install Django
pip3 install uwsgi
#Establish a connection for common commands
ln -s  /usr/local/python3.7.2/bin/django-admin /usr/bin/django-admin
ln -s  /usr/local/python3.7.2/bin/uwsgi /usr/bin/uwsgi

Install nginx

wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2/
./configure --prefix=/usr/local/nginx-1.14.2 --with-pcre \
--with-http_ssl_module --with-http_gzip_static_module \
--with-http_stub_status_module
#All associated items have been installed in the pre installation. If there is an error, copy the corresponding program search directly
make & make install

Preliminary configuration and testing of uwsgi and Django functions

Test uwsgi function

#Create a new python file for? Uwsgi.py
def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return "Hello World"
#Terminal operation
uwsgi --http :8001 --wsgi-file for_uwsgi.py
#Any browser input IP:8001 for example, your IP is 155.155.155.155:8001
#Basically, as long as it doesn't show that the server rejects the connection, it's OK

Test Django function

django-admin startproject mysite
cd mysite
python manage.py runserver 0.0.0.0:8002
#Any browser input IP:8002 for example, your IP is 155.155.155.155:8002

You may need to add 'IP' to allowed hosts
Here we need to go to the project directory and find settings.py. Modify allowed hosts. You can directly change the value to '*', or add the current IP address.

Initial official use!

Posted by EchoFool on Sun, 01 Dec 2019 07:34:10 -0800