Tencent Cloud CentOS+Django+Python+Nginx+Uwsgi deployment (for personal use, simple record)

Note: I do front-end research and development, recently studied the background Django framework, and deployed to the service of the whole process, in order to avoid forgetting later, write a simple document to record.

First: buy a server

I bought the cheapest cloud in Tencent with the lowest configuration, which mainly focuses on learning. One month’s purchase: 62.5.

Second: Log in to the terminal and install the software

My installation is in accordance with the online tutorial to, commonly known as the network porter.

1: Centos Python3 is installed

Centos7 install PYTHon3. Yum install libffi-devel-y (解决 : ModuleNotFoundError: No module named ‘_ctypes’) I installed Python3 in a slightly different version and way: the Python version used 3.7.3; Download the python-3.2.3. TGZ installation file and install it.

2: Centos installs MySql

Centos7 + Django + PYTHon3 +mysql+ Ali cloud deployment project process I’ll just use the MySql installation section here.

My process
  • Download mysql source installation package:wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  • Mysql > install mysqlyum localinstall mysql57-community-release-el7-8.noarch.rpm
  • Mysql > install mysqlyum install mysql-devel
  • MySQL > install MySQLyum install mysql-community-server
  • Execute command:pip3 install mysqlclient
  • Start MYSQL service:systemctl start mysqld
  • Check MYSQLd startup status:systemctl status mysqld
  • Startup:systemctl enable mysqld
  • Change the root local login password:
  • Obtain password:grep 'temporary password' /var/log/mysqld.log
  • Enter the mysql:mysql -uroot -p
  • Set password:Set password for 'root'@'localhost'=password(' your database password ');
  • Create a database (to match your project data) :create database testdjango;(May have Chinese problems)
  • Create database:Create database Database name character set UTF8 COLLate UTF8_general_CI;
  • Using a database:use testdjango;
  • View the current database:show databases;
  • Delete database:Drop database Specifies the database name.

3: PIP installs some software

This is the easy step, the PIP installation.

My PIP installation

Deploying Django+uWSGI+Nginx on CentOS7 I’ll just use the PIP installation section here.

  • Execute command:pip3 install uwsgi
  • Validation:uwsgi --versionMine is: 2.0.18
  • Execute command:pip3 install django
  • Validation:django-admin help
  • Execute command:yum install nginx
  • Validation:nginx -V
  • The relevant software has been installed by this point
  • Execute command:nginx
  • Open IP in a browser and “Welcome to Nginx on Fedora” means nginx started successfully.

Third, modify the corresponding configuration file

1: Modify the nginx.conf file in the /etc/nginx/ directory. Modify the following

  • listen 8099;(8099 is the custom port number, your own Settings, later request is used for this port)
  • server_name xxx.xxx.xxx.xxx;(Public IP address on Tencent Cloud)
  • location /{}; Add two lines to the braces:include uwsgi_params; Uwsgi_pass 127.0.0.1:8000;, port number 8000 is also set by myself, and the projectuwsgi.iniCongruence in)
  • At this point nginx is configured.

2: Create a Django project and configure the uwsgi.ini file.

Uwsgi services start (start) stop (reload). At the same time, create the uwsgi_params file in the project root directory, the same directory as manage.py, with the specific content: Nginx.

3: Starts the service

  • To switch to the project address, execute:uwsgi --ini uwsgi.ini
  • Perform:nginx

4: The admin background style disappears

Django+Nginx+uWSGI deployed to the server admin backend style disappeared

Fourth: Conclusion

There are many similar tutorials on the Internet, but there is always one that suits you. I am also the first time to contact the back end of things, encountered a lot of pits, we check more information, try more there is always a way to solve.

  • Remote server to create database, project root directory
  • Execute command:python manage.py makemigrations
  • Execute command:python manage.py migrate
  • Start the UWSGi service
  • Execute command:ps -ef|grep uwsgi
  • Perform:uwsgi --ini uwsgi.ini
  • Start the nginx service
  • Execute command:ps -ef|grep nginx
  • Execute command:nginx
  • Stop nginx service:pkill -9 nginx
  • Note: the value of uwsgi.pid under UWSgi must be the same as that of the command:ps -ef|grep uwsgiThe same as