1. Official repository installation

For now, the packages are only available for CentOS / RHEL 6 and 7.

Create the repository configuration, read CentOS Packages in official documentation.

[unit]
name=unit repo
baseurl=https://packages.nginx.org/unit/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Edite: the main unit package is now also available in my repository, so the official upstream repository is no more mandatory. It includes changes from PR #212 et #215 under review.

2. Remi repository installation

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

3. Server and modules installation

Install theNGINX unit server and various PHP modules. The unit-php package provides the module for the system default php.

# yum install unit unit-php php56-unit-php php71-unit-php php72-unit-php php73-unit-php

4. Test configuration

4.1 Preparation

This configuration create a listener for each PHP version,listening on a different port(8300, 8356, ...) and an application serving the usual web application directory.

Download the unit.config file:

{
	"applications": {
		"exphp": {
			"type": "php",
			"user": "nobody",
			"processes": 2,
			"root": "/var/www/html",
			"index": "index.php"
		},
		"exphp56": {
			"type": "php 5.6",
			"user": "nobody",
			"processes": 2,
			"root": "/var/www/html",
			"index": "index.php"
		},
		"exphp71": {
			"type": "php 7.1",
			"user": "nobody",
			"processes": 2,
			"root": "/var/www/html",
			"index": "index.php"
		},
		"exphp72": {
			"type": "php 7.2",
			"user": "nobody",
			"processes": 2,
			"root": "/var/www/html",
			"index": "index.php"
		},
		"exphp73": {
			"type": "php 7.3",
			"user": "nobody",
			"processes": 2,
			"root": "/var/www/html",
			"index": "index.php"
		}
	},
	"listeners": {
		"*:8300": {
			"application": "exphp"
		},
		"*:8356": {
			"application": "exphp56"
		},
		"*:8371": {
			"application": "exphp71"
		},
		"*:8372": {
			"application": "exphp72"
		},
		"*:8373": {
			"application": "exphp73"
		}
	}
}

4.2 Run the service:

# systemctl start unit

4.3 Configuration

Configuration is managed through a REST API:

# curl -X PUT --data-binary @unit.config --unix-socket /var/run/unit/control.sock http://localhost/config
{
    "success": "Reconfiguration done."
}

And to check running configuration:

# curl --unix-socket /var/run/unit/control.sock http://localhost/config

5 Usage

You can access the application on each new port:

  • http://localhost:8300/ for default PHP
  • http://localhost:8356/ for PHP version 5.6
  • http://localhost:8372/ for PHP version 7.2
  • etc

The phpinfo page will display language informations, to be noticed, in this case, Serveur API is unit.

6. Conclusion

As this is a application server, we'll probably plug it behing a web frontal (Apache HHTP server or NGINX).

This project seems interesting, but is quite young (the first version 1.2 available on github was released on june 2018); will see what the user feedback will be.

Current version is 1.7.

Edited: I think that this tool is particularly interesting to manage various languages and various version, so ideal with Software Collections.