Compile uWsgi with PHP

Compile uWsgi with PHP

uWsgi, is a powerfull Webgateway. It is used for interface, web server (Apache, Nginx), with application. uWsgi allow execution of many different application written in many different language (Python, Php, Java, Ruby, Go)

Its strength, is in its large modularity, is very easy write a new plugin for uWsgi, and then add new feature or support for new language. So,start compile and install it from source.

Required pakages

# C compiler
yum groupinstall 'Development Tools'

# lib required for compile uwsgi
yum install git php-embedded php-devel bzip2-devel zlib-devel libxml2-devel krb5-devel ncurses-devel gmp-devel openssl-devel libedit-devel python-devel

# additional pakages
yum install wget vim htop

Download uWsgi from source

cd /tmp
# go to and check last release
# back to old stable version
git clone
git checkout (LAST_VERSION)

Configure uWsgi for PHP, Python

uWsgi's build system will automatically copy file into related folder. For improving flexibility of uWsgi developer use custom python script, all build systemd work without Autogen or Automake.

cd buildconf # Forlder with base configurations
cp base.ini myconf.ini

Then copy base configuration, and edit it adding required plugins. If we embed it in uWsgi we will gain speed. If we compile it as plugin we gain in flexibility.It important change default plugin directory, because it by default is set to . You can choose plugin library folder i suggest choose between this:

  • /usr/local/lib/uwsgi_plugin
  • /usr/lib/uwsgi_plugin
xml = auto
yaml = true
json = auto
ssl = auto
pcre = auto
routing = auto
debug = false
unbit = false
malloc_implementation = libc
extras =
plugins =
bin_name = uwsgi
append_version =
plugin_dir = /usr/local/lib/uwsgi_plugin
embedded_plugins = %(main_plugin)s, ping, cache, nagios, rrdtool, carbon, rpc, corerouter, fastrouter, http, ugreen, signal, syslog, rsyslog, logsocket, router_uwsgi, router_redirect, router_basicauth, zergpool, redislog, mongodblog, router_rewrite, router_http, logfile, router_cache, rawrouter, router_static, sslrouter, spooler, cheaper_busyness, symcall, transformation_tofile, transformation_gzip, transformation_chunked, transformation_offload, router_memcached, router_redis, router_hash, router_expires, router_metrics, transformation_template, stats_pusher_socket, router_fcgi,php,python
as_shared_library = false

locking = auto
event = auto
timer = auto
filemonitor = auto

blacklist =
whitelist =

embed_files =

embed_config =

For install and compile uWsgi use this command

# compile and  install uwsgi

# name of configuration that you want compile
export UWSGI_PROFILE="NomeTuaConf.ini" 
python install

Talk about uWsgi in emperor mode

If we choose uWsgi, with multiple plugin is because we want deploy some different application on single server. The emperor mode fill perfect ours need.

uWsgi master configuration

pidfile = /run/uwsgi/
emperor = /etc/uwsgi.d
plugins-dir = /usr/local/lib/uwsgi_plugin
plugins = php

stats = /run/uwsgi/stats.sock
cap = setgid,setuid

Vassal configuration

uWsgi now is ready for spawn new vassal. Every vassal is a different application; it will launch application in separated process and could also drop privilege of vassal.

This is a example of configuration file, for launch vassal with PHP plugin.


harakiri = 120
socket = /run/uwsgi/%(project).sock

This configuration file must be saved into /etc/uwsgi.d folder.

Usefully best practice, is save all uwsgi's configurations file into application folder, then link to uwsgi.d with symbolic link

For restart vassal systemadmin must touch ini file. touch /etc/uwsgi.d/myproject.ini

Configure Nginx uWsgi PHP

server {
        root /var/www/wordpress;
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;

        location / {
                try_files $uri $uri/ /index.php?$args;

        location ~ \.php$ {
            root /var/www/wordpress;
	        include uwsgi_params;
            uwsgi_modifier1 14;
            uwsgi_pass unix:///run/uwsgi/test.sock;        

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;

Nginx configuration is standard configuration.