Guide to install uWsgi PHP, Python CentOs

Guide to install uWsgi PHP, Python CentOs

Introduction

uWSGI is a power full webgateway, it could launch many different application that could be written in many different language (Python, Django PHP).This tutorial explain how to install uWSGI as system package, and let work a wordpress installation, and django website app.

Installation of nginx

So, install nginx web server with this command:

yum install nginx

Install of uWSGI

This command install uWSGI web server

yum install uwsgi
yum install uwsgi-plugin-php uwsgi-plugin-python

Installation of MariaDB

Installation of database MariaDB:

MariaDB is more used, usually with django is better use postgresSQL, but for Wordpress is better use mysql/mariaDB.

yum install mariadb-server
systemctl start mariadb
systemctl status mariadb

systemctl enable mariadb

mysql_secure_installation

Installation of uWSGI

For install uWSGI, is enougthPer installare uwsgi, è sufficiente installare il pachetto di sistema su Centos. La documentazione ufficiale installa il pachetto tramite pip. Preferisco utilizzare il pachetto di sistema, yum terra aggiornato uwsgi, risulta più facile installare i plugin.

yum install uwsgi uwsgi-plugin-php uwsgi-plugin-python

Configure uWsgi

uWSGI Master

[uwsgi]
uid = uwsgi
gid = uwsgi
pidfile = /run/uwsgi/uwsgi.pid
emperor = /etc/uwsgi.d
stats = /run/uwsgi/stats.sock
chmod-socket = 660
emperor-tyrant = true
cap = setgid,setuid

Change configuration for store in /run/uwsgi, all socket systemd will create it.

Systemd Unit

[Unit]
Description=uWSGI Emperor Service
After=syslog.target

[Service]
EnvironmentFile=-/etc/sysconfig/uwsgi
ExecStartPre=/bin/mkdir -p /run/uwsgi
ExecStartPre=/bin/chown -R nginx:nginx /run/uwsgi
ExecStartPre=/bin/chown -R nginx:nginx /var/log/uwsgi
ExecStartPre=/bin/chown -R nginx:nginx /var/venv

ExecStartPre=/bin/chcon -R system_u:object_r:httpd_log_t:s0 /var/log/uwsgi
ExecStartPre=/bin/chcon system_u:object_r:httpd_exec_t:s0 /usr/bin/uwsgi

ExecStart=/usr/sbin/uwsgi --ini /etc/uwsgi.ini
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

uWsgi  vassal configuration

[uwsgi]
projectname 	= PRJ_NAME

plugin    	= python

# config
chdir		= /var/www/domain.com/blog
socket 		= /run/uwsgi/domain.com.sock
wsgi-file 	= %(projectname)/wsgi.py
env 		= DJANGO_SETTINGS_MODULE=%(projectname).settings_deploy
home           = /var/venv/blog.domain.com
logto 		= /var/log/uwsgi/domain.com.log
vacuum 		= true


# Worker handling
cheaper-algo=spare
cheaper=1
cheaper-initial=2
processes=4
cheaper-step=1