The first step for using NGINX Unit is installing it. NGINX Unit can be installed on a wide variety of systems. This chapter will detail how to install Unit on the major Linux distributions such as Debian, Ubuntu, Red Hat, CentOS, and Amazon Linux through NGINX package repositories. Other installation methods, such as compiling from source and using third-party repositories, are also included to enable success with NGINX Unit on virtually any Linux-based platform.
Create a file named /etc/yum.repos.d/unit.repo that contains the following contents:
[unit] name=unit repo baseurl=https://packages.nginx.org/unit/OS/$releasever/$basearch/ gpgcheck=0 enabled=1
Alter the file, replacing OS
at the end of the URL with rhel
, centos
, amzn
, or amzn2
, depending on your distribution.
Install the Unit base package:
sudo yum install unit
Install additional modules that you may want to use with Unit:
RHEL-like systems version 6.x:
sudo yum install unit-devel unit-jsc8 unit-php unit-python
For RHEL-like systems version 7.x and 8.x, you must specify versions of some language modules:
sudo yum install unit-devel unit-jsc8 unit-jsc11
unit-perl unit-php unit-python27 unit-python36
The file you just created for this solution instructs the yum
package management system to utilize the Official NGINX Unit package repository. The command that follows installs Unit from the Official repository, as well as the Unit modules needed for each application language you may want to run.
The official packages rely on default language versions that are available for the respective systems within the same package manager ecosystem. Information on customizing language modules can be found in the section Additional Resources.
Ensure that the Advanced Package Tool (APT) system is able to use HTTPS repositories:
sudo apt install apt-transport-https
Create a file named /etc/apt/sources.list.d/unit.list that contains the following contents:
deb https://packages.nginx.org/unit/OS/ CODENAME unit deb-src https://packages.nginx.org/unit/OS/ CODENAME unit
Alter the file, replacing OS
at the end of the URL with ubuntu
or debian
, depending on your distribution. Replace CODENAME
with the code name of your system. If you don’t know the code name, the following command will output the value you need:
lsb_release -c
Codename: xenial # Example
Run the following commands to install the NGINX signing key and install Unit:
wget http://nginx.org/keys/nginx_signing.key sudo apt-key add nginx_signing.key sudo apt update sudo apt install unit
A version of the language needs to be specified for certain Unit modules. At the time of this writing, not all versions of all languages are supported across all versions of the OS. You can search for module packages available from the repository for your operating system by using the following command:
apt-cache search unit- |
grep NGINX
Install additional modules that you may want to use with Unit. The following packages are available on all Debian-based systems:
sudo apt install unit-php unit-python2.7 unit-perl
unit-ruby unit-dev unit-jsc-common unit-jsc8
The file you just created instructs the apt
package management system to utilize the Official NGINX Unit package repository. The commands that follow download the NGINX GPG package signing key and import it into apt
. Providing the APT system with the signing key enables it to validate packages from the repository. The apt update
command instructs the APT system to refresh its package listings from its known repositories. After the package list is refreshed, you can install Unit and any necessary packages from the Official NGINX repository. The search command demonstrated previously can assist in finding which language versions are available for your system.
System Requirements
Debian Package Documentation
Ubuntu Package Documentation
Unit’s Node.js package is called unit-http
. It uses Unit’s libunit library; your Node.js applications require the package to run in Unit:
sudo npm install -g --unsafe-perm unit-http
Unit’s Go language module is hosted directly by NGINX. This module enables your Go application to communicate with the Unit router process directly:
go get unit.nginx.org/go
NGINX maintains packages libraries for external applications types. These libraries must be installed for the respective application to be able to run in Unit. These examples show how to install the library or module for Node.js and Go with the default package manager for either ecosystem.
Install from a third-party repository. These named repositories are maintained by the community; NGINX has no control over or responsibility for these resources.
These third-party repositories are maintained by the community. They may not contain the latest versions and can be subject to change.
sudo apk update sudo apk upgrade sudo apk add unit sudo apk add unit-openrc unit-perl unit-php7 unit-python3 unit-ruby
sudo pacman -S git
git clone https://aur.archlinux.org/nginx-unit.git
cd
nginx-unit
makepkg -si
sudo pkg install -y unit
sudo emerge --sync sudo emerge www-servers/nginx-unit
Remi’s RPM repository hosts the latest version of PHP for RHEL and its derivatives, such as CentOS and Fedora:
sudo yum install --enablerepo=
remi unitphp54-unit-php php55-unit-php php56-unit-php
php70-unit-php php71-unit-php php72-unit-php php73-unit-php
This section has detailed the usage of a number of third-party repositories maintained by the community. It is possible to utilize this information to quickly install prebuilt Unit and Unit module packages on systems that NGINX Inc. does not yet maintain a repository for. Also, the Remi repository contains specific older PHP versions that may be useful to some readers.
System Requirements
Community Repositories Install Documentation
You need to install Unit from source code.
You will have to install the packages needed to compile from source. The following includes all the development packages for all supported languages; skip the packages that you are not going to use.
For Debian and Ubuntu:
sudo apt install build-essential sudo apt install golang sudo curl -sLhttps://deb.nodesource.com/setup_<Node.js version>.x
|
bash -;
apt install nodejs;
npm install -g node-gyp sudo apt install php-dev libphp-embed sudo apt install libperl-dev sudo apt install python-dev sudo apt install ruby-dev sudo apt install openjdk-8-jdk sudo apt install libssl-dev
For Amazon Linux, CentOS, RHEL, and Fedora:
sudo yum install gcc make unzip sudo yum install golang sudo curl -sLhttps://rpm.nodesource.com/setup_<Node.js version>.x
|
bash -;
yum install nodejs;
npm install -g node-gyp sudo yum install php-devel php-embedded sudo yum install perl-devel perl-libs sudo yum install python-devel sudo yum install ruby-devel sudo yum install java-1.8.0-openjdk-devel sudo yum install openssl-devel
In some cases you may need to install the Go programming language repositories, Perl itself, and the following packages: gcc-c++
, perl-ExtUtils-Embed
.
Clone or download the source code from https://github.com/nginx/unit. If you choose to download, you’ll need to unzip the package that is downloaded. Once the source is cloned or unpacked, move into the base of the project. The next example follows the download path:
curl -O https://codeload.github.com/nginx/unit/zip/master
unzip master
cd
unit-master/
Alternatively, you can download the source directly from NGINX:
curl -O https://unit.nginx.org/download/unit-1.18.0.tar.gz
tar xzf unit-1.18.0.tar.gz
cd
unit-1.18.0
You can update the version number, in the event you’re looking for a newer version of Unit.
Next, use the configure
script to prepare the source code for installing on your system. Run ./configure --help
, or ./configure <language> --help
, to fully understand the flags available. In the following example, the --prefix
option is used to specify the installation directory. Each supported language has an associated module that also needs to be built. Run the configure
script with each application type you need to build a module for:
./configure --prefix=
/opt/unit/ ./configure go --go=
/usr/local/go/bin/go ./configure perl ./configure php ./configure python ./configure ruby ./configure nodejs ./configure java
Next, use the make
command to run the Makefile created by the configure
script and install the software. You will need to run the make
command for each language. Each language has its own configuration options. Depending on the location and ownership of the --prefix
flag specified by the configure
command, you may need to run the last command with elevated privileges:
make sudo make go-install sudo make node-install sudo make install
NGINX Unit is now installed. Validate the installation by getting the help options from the binary:
sudo /opt/unit/sbin/unitd -h
3.147.42.168