NGINX Unit
v. 1.21.0

Installation§

You can install NGINX Unit in four alternative ways:

  • Choose from our official binary packages for a few popular systems. They are as easy to use as any other packaged software and suit most purposes straight out of the box.
  • If your preferred OS or language version is missing from the official package list, try third-party repositories. Be warned, though: we don’t maintain them.
  • Run our official Docker images, prepackaged with varied language combinations.
  • To fine-tune Unit to your goals, download the sources, install the toolchain, and build a custom binary from scratch; just make sure you know what you’re doing.

Prerequisites§

Unit compiles and runs on various Unix-like operating systems, including:

  • FreeBSD 10 or later
  • Linux 2.6 or later
  • macOS 10.6 or later
  • Solaris 11

It also supports most modern instruction set architectures, such as:

  • ARM
  • IA-32
  • PowerPC
  • MIPS
  • S390X
  • x86-64

App languages and platforms that Unit can run (including several versions of the same language):

  • Go 1.6 or later
  • Java 8 or later
  • Node.js 8.11 or later
  • PHP 5, 7, 8
  • Perl 5.12 or later
  • Python 2.6, 2.7, 3
  • Ruby 2.0 or later

Official Packages§

Installing a precompiled Unit binary package is best for most occasions; official binaries are available for:

  • Amazon Linux, Amazon Linux 2
  • CentOS 6, 7, 8
  • Debian 8, 9, 10
  • Fedora 28, 29, 30, 31, 32
  • RHEL 6, 7, 8
  • Ubuntu 16.04, 18.04, 18.10, 19.04, 19.10, 20.04, 20.10

The packages we provide include core executables, developer files, and support for individual languages.

We also maintain an official Homebrew tap for macOS users.

Note

Unit’s language module for Node.js is available at the npm registry.

Note

For details of packaging custom modules that install alongside the official Unit, see here.

Amazon Linux§

Supported architectures: x86-64.

  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/amzn2/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-perl \
          unit-php unit-python27 unit-python37
    
  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/amzn/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-perl unit-php \
          unit-python27 unit-python34 unit-python35 unit-python36
    

Note

The control socket’s pathname is /var/run/unit/control.sock. The log is /var/log/unit/unit.log.

CentOS§

Supported architectures: x86-64.

  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-jsc11 \
          unit-perl unit-php unit-python27 unit-python36
    

Warning

Unit 1.20+ packages aren’t available for CentOS 6. This distribution is obsolete; please update.

Supported architectures: i386, x86-64.

  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-php unit-python
    

Note

The control socket’s pathname is /var/run/unit/control.sock. The log is /var/log/unit/unit.log.

Debian§

Supported architectures: i386, x86-64.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/debian/ buster unit
    deb-src https://packages.nginx.org/unit/debian/ buster unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc11 unit-perl \
          unit-php unit-python2.7 unit-python3.7 unit-ruby
    
  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/debian/ stretch unit
    deb-src https://packages.nginx.org/unit/debian/ stretch unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc8 unit-perl \
          unit-php unit-python2.7 unit-python3.5 unit-ruby
    

Warning

Unit 1.12+ packages aren’t available for Debian 8. This distribution is obsolete; please update.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/debian/ jessie unit
    deb-src https://packages.nginx.org/unit/debian/ jessie unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-perl unit-php unit-python2.7 \
          unit-python3.4 unit-ruby
    

Note

The control socket’s pathname is /var/run/control.unit.sock. The log is /var/log/unit.log.

Fedora§

Supported architectures: x86-64.

  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/fedora/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc11 unit-jsc8 unit-perl \
          unit-php unit-python38 unit-ruby
    
  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/fedora/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc11 unit-jsc8 unit-perl \
          unit-php unit-python27 unit-python37 unit-ruby
    
  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/fedora/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-perl \
          unit-php unit-python27 unit-python37 unit-ruby
    

Warning

Unit 1.12+ packages aren’t available for Fedora 28. This distribution is obsolete; please update.

  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/fedora/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-perl \
          unit-php unit-python27 unit-python36 unit-ruby
    

Note

The control socket’s pathname is /var/run/unit/control.sock. The log is /var/log/unit/unit.log.

RHEL§

Supported architectures: x86-64.

  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/rhel/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and other packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-jsc11 \
          unit-perl unit-php unit-python27 unit-python36
    

Supported architectures: i386, x86-64.

  1. To configure Unit repository, create the following file named /etc/yum.repos.d/unit.repo:

    [unit]
    name=unit repo
    baseurl=https://packages.nginx.org/unit/rhel/$releasever/$basearch/
    gpgcheck=0
    enabled=1
    
  2. Install the core package and additional packages you need:

    # yum install unit
    # yum install unit-devel unit-go unit-jsc8 unit-perl \
          unit-php unit-python
    

Note

The control socket’s pathname is /var/run/unit/control.sock. The log is /var/log/unit/unit.log.

Ubuntu§

Supported architectures: arm64, x86-64.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/ubuntu/ groovy unit
    deb-src https://packages.nginx.org/unit/ubuntu/ groovy unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc11 unit-jsc13 unit-jsc14 unit-jsc15 \
                  unit-perl unit-php unit-python3.8 unit-ruby
    

Supported architectures: arm64, x86-64.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/ubuntu/ focal unit
    deb-src https://packages.nginx.org/unit/ubuntu/ focal unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc11 unit-perl \
          unit-php unit-python2.7 unit-python3.8 unit-ruby
    

Warning

Unit 1.20+ packages aren’t available for Ubuntu 19.10. This distribution is obsolete; please update.

Supported architectures: x86-64.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/ubuntu/ eoan unit
    deb-src https://packages.nginx.org/unit/ubuntu/ eoan unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc11 unit-perl \
          unit-php unit-python2.7 unit-python3.7 unit-python3.8 unit-ruby
    

Supported architectures: x86-64.

Warning

Unit 1.16+ packages aren’t available for Ubuntu 19.04. This distribution is obsolete; please update.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/ubuntu/ disco unit
    deb-src https://packages.nginx.org/unit/ubuntu/ disco unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc11 unit-perl \
          unit-php unit-python2.7 unit-python3.7 unit-ruby
    

Supported architectures: x86-64.

Warning

Unit 1.12+ packages aren’t available for Ubuntu 18.10. This distribution is obsolete; please update.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/ubuntu/ cosmic unit
    deb-src https://packages.nginx.org/unit/ubuntu/ cosmic unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go1.10 unit-jsc8 unit-jsc11 unit-perl \
          unit-php unit-python2.7 unit-python3.6 unit-python3.7 unit-ruby
    

Supported architectures: arm64, x86-64.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/ubuntu/ bionic unit
    deb-src https://packages.nginx.org/unit/ubuntu/ bionic unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc8 unit-jsc11 unit-perl \
          unit-php unit-python2.7 unit-python3.6 unit-python3.7 unit-ruby
    

Supported architectures: arm64, i386, x86-64.

  1. Download NGINX’s signing key and add it to apt’s keyring:

    # curl -sL https://nginx.org/keys/nginx_signing.key | apt-key add -
    

    This eliminates the ‘packages cannot be authenticated’ warnings during installation.

  2. To configure Unit repository, create the following file named /etc/apt/sources.list.d/unit.list:

    deb https://packages.nginx.org/unit/ubuntu/ xenial unit
    deb-src https://packages.nginx.org/unit/ubuntu/ xenial unit
    
  3. Install the core package and other packages you need:

    # apt update
    # apt install unit
    # apt install unit-dev unit-go unit-jsc8 unit-perl unit-php \
          unit-python2.7 unit-python3.5 unit-ruby
    

Note

The control socket’s pathname is /var/run/control.unit.sock. The log is /var/log/unit.log.

Homebrew§

To install Unit on macOS from our official Homebrew tap:

$ brew install nginx/unit/unit

This deploys the core Unit binary and the prerequisites for Go and Node.js language module installation.

To install Java, Perl, Python, and Ruby language modules from Homebrew:

$ brew install unit-java unit-perl unit-python unit-python3 unit-ruby

Note

The control socket’s pathname is /usr/local/var/run/unit/control.sock.
The log is /usr/local/var/log/unit/unit.log.

Go§

To install the Go language module:

$ go get unit.nginx.org/go

That’s it; now, you can use it to run your Go apps in Unit.

Node.js§

Unit’s npm-hosted Node.js module is unit-http. Your Node.js apps must require it to run in Unit:

  1. First, install the unit-dev/unit-devel package, necessary to build unit-http.

  2. Next, build and install unit-http globally (this step requires npm and node-gyp):

    # npm install -g --unsafe-perm unit-http
    

    Warning

    The unit-http module is platform dependent due to optimizations; you can’t move it across systems with the rest of node-modules. Global installation avoids such scenarios; just relink the migrated app.

  3. After that, use the module in your Node.js app instead of the built-in http to run it in Unit. Mind that such frameworks as Express may require extra changes in your code.

If you update Unit later, make sure to update the module as well:

# npm update -g --unsafe-perm unit-http

Note

You can also configure and install the unit-http module from sources.

Startup and Shutdown§

Run unitd -h or unitd --version to verify Unit is available or list its settings. To manage the installation:

Enable Unit to launch automatically at system startup:

# systemctl enable unit

Start or restart Unit:

# systemctl restart unit

Stop a running Unit:

# systemctl stop unit

Disable Unit’s automatic startup:

# systemctl disable unit

Start Unit as a daemon:

# unitd

Stop all Unit processes:

# pkill unitd

Community Repositories§

Warning

These distributions are maintained by respective communities, not NGINX. Proceed with caution.

To install core Unit executables from the Alpine Linux packages:

# apk update
# apk upgrade
# apk add unit

To install service manager files and specific language modules:

# apk add unit-openrc unit-perl unit-php7 unit-python3 unit-ruby

Runtime details:

Control socket/run/control.unit.sock
Log file/var/log/unit.log
Non-privileged userunit
Startup and shutdown
# service unit start
# service unit stop

To install core Unit executables and all language modules, clone the Arch User Repository (AUR):

$ git clone https://aur.archlinux.org/nginx-unit.git
$ cd nginx-unit

Before proceeding further, verify that the PKGBUILD and the accompanying files aren’t malicious or untrustworthy. AUR packages are user produced without pre-moderation; use them at your own risk.

Next, build the package:

$ makepkg -si

Runtime details:

Control socket/run/nginx-unit.control.sock
Log file/var/log/nginx-unit.log
Non-privileged usernobody
Startup and shutdown
# systemctl start unit
# systemctl stop unit

If you use SCLo Software Collections in your environment, you can install Unit’s PHP modules as packages from the corresponding repo. Besides other dependencies, the packages require the core Unit installation.

CentOS:

# yum install centos-release-scl
# yum install --enablerepo=centos-sclo-sclo \
              sclo-php72-unit-php sclo-php73-unit-php

RHEL:

# cd /etc/yum.repos.d/
# curl -O https://copr.fedorainfracloud.org/coprs/rhscl/centos-release-scl/repo/epel-7/rhscl-centos-release-scl-epel-7.repo
# yum install centos-release-scl
# yum install --enablerepo=centos-sclo-sclo \
              sclo-php72-unit-php sclo-php73-unit-php

To install Unit from FreeBSD packages, install the core package and other packages you need:

# pkg install -y unit
# pkg install -y libunit
# pkg install -y unit-java8  \
                 unit-perl5.32  \
                 unit-php72 unit-php73 unit-php74 unit-php80  \
                 unit-python27 unit-python37  \
                 unit-ruby2.6

To install Unit from FreeBSD ports, start by updating your port collection.

With portsnap:

# portsnap fetch update

With svn:

# svn update /usr/ports

Next, browse to the port path to build and install the core Unit port:

# cd /usr/ports/www/unit/
# make
# make install

Repeat the steps for the other ports you need: libunit (required to install the Node.js module and build Go apps), unit-java, unit-perl, unit-php, unit-python, or unit-ruby.

Runtime details:

Control socket/var/run/unit/control.unit.sock
Log file/var/log/unit/unit.log
Non-privileged userwww
Startup and shutdown
# service unitd start
# service unitd stop

To install Unit using Portage, update the repository and install the package:

# emerge --sync
# emerge www-servers/nginx-unit

To install specific language modules and features, apply the corresponding USE flags.

Runtime details:

Control socket/run/nginx-unit.sock
Log file/var/log/nginx-unit
Non-privileged usernobody
Startup and shutdown
# openrc -s nginx-unit start
# openrc -s nginx-unit stop

To install core Unit executables and all language modules using the Nix package manager, update the channel, check if Unit’s available, and install the package:

$ nix-channel --update
$ nix-env -qa 'unit'
$ nix-env -i unit

This installs most embedded language modules and such features as SSL or IPv6 support. For a full list of optionals, see the package definition.

Runtime details:

Control socket/run/unit/control.unit.sock
Log file/var/log/unit/unit.log
Non-privileged userunit
Startup and shutdownManual

Remi’s RPM repository, which hosts the latest versions of the PHP stack for CentOS, Fedora, and RHEL, also has the core Unit package and the PHP modules.

To use Remi’s versions of Unit packages, configure Remi’s RPM repo first. Remi’s PHP language modules are also compatible with the core Unit package from our own repository.

Next, install Unit and the PHP modules you want:

# yum install --enablerepo=remi unit  \
      php54-unit-php php55-unit-php php56-unit-php  \
      php70-unit-php php71-unit-php php72-unit-php php73-unit-php php74-unit-php  \
      php80-unit-php

Runtime details:

Control socket/run/unit/control.sock
Log file/var/log/unit/unit.log
Non-privileged usernobody
Startup and shutdown
# systemctl start unit
# systemctl stop unit

Docker Images§

To install and run Unit from NGINX’s Docker image repository:

$ docker pull nginx/unit
$ docker run -d nginx/unit

Default image tag is :latest; it resolves into a -full configuration of the latest Unit version. Other tags:

TagDescription
1.21.0-fullModules for all supported languages.
1.21.0-minimalNo language modules.
1.21.0-<language>A specific language module, for example 1.21.0-ruby2.3 or 1.21.0-python2.7.

We also publish these images as tarballs on our website:

$ curl -O https://packages.nginx.org/unit/docker/1.21.0/nginx-unit-1.21.0-full.tar.gz
$ curl -O https://packages.nginx.org/unit/docker/1.21.0/nginx-unit-1.21.0-full.tar.gz.sha512
$ sha512sum -c nginx-unit-1.21.0-full.tar.gz.sha512
      nginx-unit-1.21.0-full.tar.gz: OK
$ docker load < nginx-unit-1.21.0-full.tar.gz

Note

The control socket’s pathname is /var/run/control.unit.sock. The log is /var/log/unit.log.

For further details, see the repository page and the official Howto.

Initial Configuration§

Official images support initial container configuration, implemented with an ENTRYPOINT script.

First, the script checks the Unit state directory (/var/lib/unit/ in official images) of the container. If it’s empty, the script processes certain file types in the container’s /docker-entrypoint.d/ directory:

File TypePurpose/Action
.pemCertificate bundles are uploaded under respective names: cert.pem to certificates/cert.
.jsonConfiguration snippets are uploaded as to the config section of Unit’s configuration.
.shShell scripts that run in the container after the .pem and .json files are uploaded.

Note

The script issues warnings about any other file types in the /docker-entrypoint.d/ directory. Also, your shell scripts must have execute permissions set.

This mechanism allows you to customize your containers at startup, reuse configurations, and automate your workflows, reducing manual effort. To use the feature, add COPY directives for certificate bundles, configuration fragments, and shell scripts to your Dockerfile derived from an official image:

FROM nginx/unit:1.21.0-minimal
COPY ./*.pem  /docker-entrypoint.d/
COPY ./*.json /docker-entrypoint.d/
COPY ./*.sh   /docker-entrypoint.d/

Note

Mind that running Unit even once populates its state directory; this prevents the script from executing, so this script-based initialization must occur before you run Unit within your derived image.

This feature comes in handy if you want to tie Unit to a certain app configuration for later use. For ad-hoc initialization, you can mount a directory with configuration files to a container at startup:

$ docker run -d --mount \
         type=bind,src=/path/to/config/files/,dst=/docker-entrypoint.d/ \
         nginx/unit:latest)

Source Code§

Obtaining Sources§

You can get Unit source code from our official Mercurial repository, its GitHub mirror, or in a tarball.

If you’d like to use Mercurial:

$ hg clone https://hg.nginx.org/unit
$ cd unit

If you prefer Git:

$ git clone https://github.com/nginx/unit
$ cd unit

To download sources directly from our site:

$ curl -O https://unit.nginx.org/download/unit-1.21.0.tar.gz
$ tar xzf unit-1.21.0.tar.gz
$ cd unit-1.21.0

Installing Required Software§

Before configuring and compiling Unit, install the required build tools plus the library files for available languages (Go, Node.js, PHP, Perl, Python, and Ruby) and other features you want Unit to support.

The commands below assume you are configuring Unit with all supported languages and features; otherwise, skip the packages you aren’t going to use.

# apt install build-essential
# apt install golang
# curl -sL https://deb.nodesource.com/setup_version.x | bash -
# apt install nodejs
# npm install -g node-gyp
# apt install php-dev libphp-embed
# apt install libperl-dev
# apt install python-dev
# apt install ruby-dev
# apt install openjdk-8-jdk
# apt install libssl-dev
# apt install libpcre2-dev
# yum install gcc make
# yum install golang
# curl -sL https://rpm.nodesource.com/setup_version.x | bash -
# yum install nodejs
# npm install -g node-gyp
# yum install php-devel php-embedded
# yum install perl-devel perl-libs
# yum install python-devel
# yum install ruby-devel
# yum install java-1.8.0-openjdk-devel
# yum install openssl-devel
# yum install pcre2-devel

Ports:

# cd /usr/ports/lang/go/ && make install clean
# cd /usr/ports/www/node/ && make install clean
# cd /usr/ports/www/npm/ && make install clean && npm i -g node-gyp
# cd /usr/ports/lang/php73/ && make install clean
# cd /usr/ports/lang/perl5.28/ && make install clean
# cd /usr/ports/lang/python/ && make install clean
# cd /usr/ports/lang/ruby25/ && make install clean
# cd /usr/ports/java/openjdk8/ && make install clean
# cd /usr/ports/security/openssl/ && make install clean
# cd /usr/ports/devel/pcre/ && make install clean

Packages:

# pkg install go
# pkg install node && pkg install npm && npm i -g node-gyp
# pkg install php73
# pkg install perl5
# pkg install python
# pkg install ruby25
# pkg install openjdk8
# pkg install openssl
# pkg install pcre2
# pkg install gcc
# pkg install golang
# pkg install php-71
# pkg install ruby
# pkg install jdk-8
# pkg install openssl
# pkg install pcre

Also, use gmake instead of make when building and installing Unit on Solaris.

Configuring Sources§

To run system compatibility checks and generate a Makefile with core build instructions for Unit:

$ ./configure <command-line options>

To finalize the resulting Makefile, configure the language modules you need.

General options and settings that control compilation, runtime privileges, or support for certain features:

--help

Displays a summary of common ./configure options.

For language-specific details, run ./configure <language> --help or see below.

--cc=pathname

Custom C compiler pathname.

The default is cc.

--cc-opt=options, --ld-opt=optionsExtra options for the C compiler and linker.
--group=name, --user=name

Group name and username to run Unit’s non-privileged processes.

The defaults are --user’s primary group and nobody, respectively.

--debugTurns on the debug log.
--no-ipv6Turns off IPv6 support.
--no-unix-socketsTurns off Unix domain sockets support.
--openssl

Turns on OpenSSL support. Make sure that OpenSSL (1.0.1 and later) header files and libraries are available in your compiler’s search path.

To customize the path, provide the --cc-opt and --ld-opt options; you can also set the CFLAGS and LDFLAGS environment variables before running ./configure.

For details, see SSL/TLS and Certificates.

By default, Unit relies on PCRE2 to support regular expessions in routes. These flags alter its behavior:

--no-regexTurns off regex support. Attempts to configure a regex will fail validation.
--no-pcre2Instead of PCRE2, the older PCRE 8.x library will be used.

The next option group customizes Unit’s runtime directory structure:

--prefix=prefix

Destination directory prefix for path options: --bindir, --sbindir, --libdir, --incdir, --modules, --state, --pid, --log, and --control.

--bindir=directory, --sbindir=directory

Directory paths for end-user and sysadmin executables.

The defaults are bin and sbin, respectively.

--control=socket

Control API socket address in IPv4, IPv6, or Unix domain format:

$ ./configure --control=unix:/path/to/control.unit.sock
$ ./configure --control=127.0.0.1:8080
$ ./configure --control=[::1]:8080

Warning

Avoid exposing an unprotected control socket to public networks. Use NGINX or a different solution such as SSH for security and authentication.

The default is unix:control.unit.sock, created as root with 600 permissions.

--incdir=directory, --libdir=directory

Directory paths for libunit header files and libraries.

The defaults are include and lib, respectively.

--log=pathname

Pathname for Unit’s log.

The default is unit.log.

--modules=directory

Directory path for Unit’s language modules.

The default is modules.

--pid=pathname

Pathname for the PID file of Unit’s daemon process.

The default is unit.pid.

--state=directory

Directory path where Unit’s state (configuration, certificates, other records) is stored between runs. If you migrate your installation, copy the entire directory.

Warning

Unit’s state includes sensitive data and must be owned by root with 700 permissions. Avoid updating the directory by outside means; instead, use Unit’s config API to ensure data consistency.

The default is state.

--tmp=directory

Defines the temporary files location (used to dump large request bodies).

The default value is tmp.

Directory Structure§

To customize Unit installation and runtime directories, you can both:

  • Set the --prefix and path options (their relative settings are prefix-based) during configuration to set up the runtime file structure: Unit uses these settings to locate its modules, state, and other files.
  • Set the DESTDIR variable during installation. Unit’s file structure is placed at the specified directory, which can be either the final installation target or an intermediate staging location.

Coordinate these two options as necessary to customize the directory structure. One common scenario is installation based on absolute paths:

  1. Set absolute runtime paths with --prefix and path options:

    $ ./configure --state=/var/lib/unit --log=/var/log/unit.log \
                  --control=unix:/run/control.unit.sock --prefix=/usr/local/
    

    Configured thus, Unit will store its state, log, and control socket at custom locations; other files will have default prefix-based paths. Here, unitd is put to /usr/local/sbin/, modules to /usr/local/modules/.

  2. For further packaging or containerization, specify DESTDIR at installation to place the files in a staging location while preserving their relative structure. Otherwise, omit DESTDIR for direct installation.

An alternative scenario is a build that you can move around the filesystem:

  1. Set relative runtime paths with --prefix and path options:

    $ ./configure --state=config --log=log/unit.log \
                  --control=unix:control/control.unit.sock --prefix=movable
    

    Configured this way, Unit will store its files by prefix-based paths (both default and custom), for example, <working directory>/movable/sbin/ or <working directory>/movable/config/.

  2. Specify DESTDIR when installing the build. You can migrate such builds if needed; move the entire file structure and launch binaries from the base directory so that the relative paths stay valid:

    $ cd <DESTDIR>
    # movable/sbin/unitd <command-line options>
    

You can combine these approaches, but take care to understand how your settings work together.

Configuring Modules§

Next, configure a module for each language you want to use with Unit. The ./configure <language> commands set up individual language modules and place module-specific instructions in the Makefile.

Note

To run apps in several versions of a language, build and install a module for each version.

When you run ./configure go, Unit sets up the Go package that lets your applications run in Unit. To use the package, install it in your Go environment. Available configuration options:

--go=pathname

Specific Go executable pathname, also used in make targets.

The default is go.

--go-path=directory

Custom directory path for Go package installation.

The default is $GOPATH.

Note

The ./configure script doesn’t alter the GOPATH environment variable. The two paths (configuration-time --go-path and compile-time GOPATH) must be coherent at build time for Go to locate the Unit package.

When you run ./configure java, the script configures a module to support running Java Web Applications in Unit. Available command options:

--home=directory

Directory path for Java utilities and header files (required to build the module).

The default is the java.home setting.

--jars=directory

Directory path for Unit’s custom .jar files.

The default is the Java module path.

--lib-path=directory

Directory path for the libjvm.so library.

The default is based on JDK settings.

--local-repo=directory

Directory path for local .jar repository.

The default is $HOME/.m2/repository/.

--repo=directory

URL path for remote Maven repository.

The default is http://central.maven.org/maven2/.

--module=filename

Name of the module to be built (<module>.unit.so), also used in make targets.

The default is java.

To configure a module called java11.unit.so with OpenJDK 11.0.1:

$ ./configure java --module=java11 \
                   --home=/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home

When you run ./configure nodejs, Unit sets up the unit-http module that lets your applications run in Unit. Available configuration options:

--local=directory

Local directory path for Node.js module installation.

By default, the module is installed globally (recommended).

--node=pathname

Specific Node.js executable pathname, also used in make targets.

The default is node.

--npm=pathname

Specific NPM executable pathname.

The default is npm.

--node-gyp=pathname

Specific node-gyp executable pathname.

The default is node-gyp.

When you run ./configure perl, the script configures a module to support running Perl scripts as applications in Unit. Available command options:

--perl=pathname

Specific Perl executable pathname.

The default is perl.

--module=filename

Name of the module to be built (<module>.unit.so), also used in make targets.

The default is the filename of the --perl executable.

To configure a module called perl-5.20.unit.so for Perl 5.20.2:

$ ./configure perl --module=perl-5.20 \
                   --perl=perl5.20.2

When you run ./configure php, the script configures a module to support running PHP applications in Unit via PHP’s embed SAPI. Available command options:

--config=pathname

Pathname of the php-config script invoked to configure the PHP module.

The default is php-config.

--lib-path=directoryDirectory path of PHP’s embed SAPI library file (libphp<version>.so or .a).
--lib-staticLinks the static embed SAPI library (libphp<version>.a) instead of the dynamic one (libphp<version>.so); requires --lib-path.
--module=filename

Name of the module to be built (<module>.unit.so), also used in make targets.

The default is --config’s filename minus the -config suffix; thus, /path/php7-config turns into php7.

To configure a module called php70.unit.so for PHP 7.0:

$ ./configure php --module=php70 \
                  --config=/usr/lib64/php7.0/bin/php-config \
                  --lib-path=/usr/lib64/php7.0/lib64

When you run ./configure python, the script configures a module to support running Python scripts as applications in Unit. Available command options:

--config=pathname

Pathname of the python-config script invoked to configure the Python module.

The default is python-config.

--lib-path=directoryCustom directory path of the Python runtime library to use with Unit.
--module=filename

Name of the module to be built (<module>.unit.so), also used in make targets.

The default is --config’s filename minus the -config suffix; thus, /path/python3-config turns into python3.

To configure a module called py33.unit.so for Python 3.3:

$ ./configure python --module=py33 \
                     --config=python-config-3.3

When you run ./configure ruby, the script configures a module to support running Ruby scripts as applications in Unit. Available command options:

--module=filename

Name of the module to be built (<module>.unit.so), also used in make targets.

The default is the filename of the --ruby executable.

--ruby=pathname

Specific Ruby executable pathname.

The default is ruby.

To configure a module called ru23.unit.so for Ruby 2.3:

$ ./configure ruby --module=ru23 \
                   --ruby=ruby23

Building and Installing Unit§

To build and install Unit executables and language modules that you have ./configure’d earlier:

$ make
# make install

You can also build and install language modules individually; the specific method depends on whether the language module is embedded in Unit or packaged externally.

Note

For further details about Unit language modules, see Working With Language Modules.

Embedded Language Modules§

To build and install Unit modules for Java, PHP, Perl, Python, or Ruby after configuration, run make <module> and make <module>-install, for example:

$ make perl-5.20
# make perl-5.20-install

External Language Modules§

To build and install Unit modules for Go and Node.js globally after configuration, run make <go>-install and make <node>-install, for example:

# make go-install
# make node-install

Note

To install the Node.js module locally, run make <node>-local-install:

# make node-local-install

If you haven’t specified the --local directory with ./configure nodejs earlier, provide it here: DESTDIR=/your/project/directory. If both options are specified, DESTDIR prefixes the --local value.

However, mind that global installation is the recommended method for the Node.js module.

If you customize the executable pathname with --go or --node, use the following pattern:

$ ./configure nodejs --node=/usr/local/bin/node8.12
# make /usr/local/bin/node8.12-install

$ ./configure go --go=/usr/local/bin/go1.7
# make /usr/local/bin/go1.7-install

Startup§

We advise installing Unit from precompiled packages; in this case, startup is configured automatically.

Even if you install Unit otherwise, manual startup isn’t recommended. Instead, configure a service manager such as OpenRC or systemd or create an rc.d script to launch the Unit daemon using the options below.

Run unitd as root from the sbin installation subdirectory. Usually, the default compile-time settings don’t require overrides; use the --help option to review their values. For details and security notes, see here.

General options and compile-time setting overrides:

--help, -hDisplays a summary of Unit’s command-line options and their default values set at compile time.
--no-daemonRuns Unit in non-daemon mode.
--versionDisplays Unit’s version and the ./configure settings it was built with.
--control socket

Control API socket address in IPv4, IPv6, or Unix (with unix: prefix) domain format:

# unitd --control unix:/path/to/control.unit.sock
# unitd --control 127.0.0.1:8080
# unitd --control [::1]:8080
--group name, --user nameGroup name and user name used to run Unit’s non-privileged processes.
--log pathnamePathname for the Unit log.
--modules directoryDirectory path for Unit language modules (<module>.unit.so files).
--pid pathnamePathname for the PID file of Unit’s main process.
--state directoryDirectory path for Unit state storage.
n> pathnamePathname for the Unit log.--modules directoryDirectory path for Unit language modules (<module>.unit.so files).--pid pathnamePathname for the PID file of Unit’s main process.--state directoryDirectory path for Unit state storage.