Chapter 2. Installation

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.

2.1 Red Hat–Based Systems (.rpm)

Problem

You need to install NGINX Unit on Red Hat, CentOS, or Amazon Linux.

Solution

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

Discussion

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.

2.2 Debian-Based Systems (.deb)

Problem

You need to install NGINX Unit on a Debian or Ubuntu machine.

Solution

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

Discussion

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.

2.3 Go and NPM

Problem

You need to install the Go or Node.js Unit packages for Unit to hook into your application.

Solution

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

Discussion

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.

2.4 Third-Party Repositories

Problem

You want to run NGINX Unit on a system for which NGINX Inc. does not have prebuilt packages, and you do not want to build from source.

Solution

Install from a third-party repository. These named repositories are maintained by the community; NGINX has no control over or responsibility for these resources.

Third-Party Repositories

These third-party repositories are maintained by the community. They may not contain the latest versions and can be subject to change.

Alpine Linux:

sudo apk update
sudo apk upgrade
sudo apk add unit
sudo apk add unit-openrc unit-perl unit-php7 unit-python3 unit-ruby

Arch Linux:

sudo pacman -S git
git clone https://aur.archlinux.org/nginx-unit.git
cd nginx-unit
makepkg -si

FreeBSD:

sudo pkg install -y unit

Gentoo:

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 unit 
      php54-unit-php php55-unit-php php56-unit-php 
      php70-unit-php php71-unit-php php72-unit-php php73-unit-php

Discussion

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.

2.5 Installing from Source

Problem

You need to install Unit from source code.

Solution

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 -sL 
      https://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 -sL 
      https://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

Discussion

The preceding steps will build and install NGINX Unit from source. A number of configuration flags can be used to modify the build and installation. Unit is ready to use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.42.168