Detailed Explanation of Configuring python mysql nginx uwsgi and django on VPS CENTOS

  • 2021-07-06 11:26:04
  • OfStack

This paper describes the method of configuring python, mysql, nginx, uwsgi and django on VPS and CENTOS. Share it for your reference, as follows:

I tried VPS yesterday and spent 1 day deploying a simple application. In the following procedure, the step of creating project with django is omitted, and you forget to create yourself with startporject.

The following is the original operation, while recording things, I am used to text editing. Maybe the format is not good-looking. Now move to the blog.

Install GCC first.


yum -y install gcc automake autoconf libtool make

Install Chinese package for CENTOS

Check CENTOS version cat/etc/redhat-release Mine is 5.7. Look for 5.7 on the official website, but I can't find it. Use 5.5.


yum groupinstall chinese-support
vi /etc/sysconfig/i18n

The contents are as follows:


LANG="zh_CN.UTF-8"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"

Use the locale command to view the system language settings:

locale

The font library of 5.5 is used below.


wget http://ftp.dc.volia.com/pub/CentOS/5.5/os/x86_64/CentOS/fonts-chinese-3.02-12.el5.noarch.rpm
wget http://ftp.dc.volia.com/pub/CentOS/5.5/os/x86_64/CentOS/fonts-ISO8859-2-75dpi-1.0-17.1.noarch.rpm

rpm-ivh installation will not be mentioned.

Installation is complete, and then reboot

Installing python 2.7. 2


wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz

1.


./configure -with-zlib=/usr/include ( Need to see zlib.h The file is in that directory  whereis zlib.h)
make install

Step 2 Establish a soft connection


cd /usr/bin
rm -rf python
ln -s /usr/local/bin/python2.7 python

After doing so, it may cause a problem. The yum command is not available, and yum needs to be modified at this time


vi /usr/bin/yum

Modify the python path # in line 1! /usr/bin/python2.4 Because centos uses python2.4

Installing the PIL python library


wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
python setup.py install

Installing Django 1.3


wget http://www.djangoproject.com/download/1.3/tarball/
python setup.py install

Installing setuptools


yum groupinstall chinese-support
vi /etc/sysconfig/i18n

0

Installing python-mysqldb


wget http://ncu.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
yum install mysql-devel
python setup.py install

Install MYSQL (CENTOS comes with 5.0)


yum install mysql-server

MYSQL login issues:


yum groupinstall chinese-support
vi /etc/sysconfig/i18n

3

Installing UWSGI


yum groupinstall chinese-support
vi /etc/sysconfig/i18n

4

After decompression


yum groupinstall chinese-support
vi /etc/sysconfig/i18n

5

Note: When viewing data on the Internet, there are still those that need to be operated in the mode of python setup. py build. For details, please check the official website description of uwsgi.

Create a file of django_wsgi. py in your django project, such as mine under /opt/www/uploadfile


yum groupinstall chinese-support
vi /etc/sysconfig/i18n

6

Create a catalogu/home/uwsgi


vi uwsig.ini

The contents are as follows:


[uwsgi]
socket=127.0.0.1:9000
listen=200
master=true
pidfile=/usr/local/nginx/uwsgi.pid
processes=8
pythonpath=/opt/www/uploadfile
pythonpath=/opt/www/
module=django_wsgi
profiler=true
memory-report=true
enable-threads=true
logdate=true
limit-as=6048
daemonize=/opt/www/logs/django.log

Run uwsgi --ini /home/uwsgi/uwsgi.ini

Installing nginx


yum groupinstall chinese-support
vi /etc/sysconfig/i18n

9

And then


./configure

You can see the path after installation:


nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
make install

And then


cp /usr/local/nginx/sbin/nginx /usr/bin

Start nginx by running nginx.

If you want to stop


nginx -s stop

How to Restart nginx

The following command: nginx -s  reload Of course, there is also an reopen. Let's see the specific difference by yourself. I won't say it.

The next step is to configure the cooperation between nginx and django.


cd /usr/local/nginx/conf
vi django_uwsgi.conf

The contents are as follows:


server {
listen 80;
server_name 216.24.200.212;
location / {
   uwsgi_pass 127.0.0.1:9000;
   include uwsgi_params;
   access_log off;
}
location ^~ /static {
  root /opt/www/uploadfile;
}
location ^~ /admin/ {
   uwsgi_pass 127.0.0.1:9000;
   include uwsgi_params;
   access_log off;
}
location ~* ^.+\.
(mpg|avi|mp3|swf|zip|pdf|jpg|gif|png|bmp|jpeg|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg|js|css)$ {
   root /opt/www/uploadfile/static;
   access_log off;
}
}

Then open nginx. conf editing and add the following in http {}:


include django_uwsgi.conf;
client_max_body_size 20m; # This is used to control the uploaded file size 

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

View process


ps -ef|grep uwsgi|grep -v grep

If uwsgi is not started, do the following


uwsgi --ini /home/uwsgi/uwsgi.ini

Listening port (9000 used in my configuration file)


netstat -an|grep 9000
nginx -s reload

Open a web page to view it, such as

http://myipaddress

I hope this paper is helpful to the Python programming based on Django framework.


Related articles: