> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/sdks/backend-sdk/selphid/installation/installation_instructions.md).

# SDK installation and deployment

## 1. Introduction

This document describes the components provided in the product **FacePhi SelphID SDK**.

This product includes several libraries whose APIs allow you to integrate features into your biometric authentication and identification solutions that use facial images and/or templates, passive liveness detection, data validation, and information extraction from identity documents.

The following sections describe the components provided and the steps required to install the SDK on **Windows** and **Linux**.

## 2. SelphID SDK Contents

The Software Development Kit, **FacePhi SelphID SDK**, contains a set of libraries for the Java, .NET, and C++ programming languages that allow developers to integrate the main features offered by this product:

* Reading and validating information from digital identity documents (OCR).
* User authentication (1:1) and identification (1:N) using facial recognition with images or templates.
* Passive user liveness detection using images (without requiring user cooperation).

The contents of **SelphID SDK** are as follows:

* Libraries for the C++, Java, and .NET programming languages (.NET is only available in the Windows version).
* Java API and .NET API documentation, both in HTML format, with information about all the methods supported by each class.
* Product license configuration file, as well as usage and log files.
* Web service programming examples in .NET/Java.
* C++ header files.

Different products are provided for the Windows and Linux operating systems.

* Products available for Windows.
* **fphi-selphid-sdk-win64\_x.x.x.x** (64-bit Windows).
* Products available for Linux.
* **fphi-selphid-sdk-linux64\_x.x.x.x** (Linux Ubuntu-based distributions).

{% hint style="info" %}
**x.x.x.x** may vary and corresponds to the product version provided by **FacePhi**.
{% endhint %}

![](https://865101184-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUo71Qbj6jZQDavjc0U5X%2Fuploads%2Fgit-blob-411de99dd1eea7a1d8c86ceab46578f73170bdc9%2Farq_sdk.png?alt=media)

## 3. SDK Installation

This chapter describes the steps to install SelphID SDK.

### 3.1 Installing the Software Development Kit

Install SelphID SDK by extracting the provided contents to a directory on your system. The recommended directories are as follows:

* Recommended installation directories on Windows: **C:\Program Files\FacePhi\Sdk\SelphId\x.x.x.x**
  * To extract the Windows SDK, simply extract the ZIP file to the specified path.
* Recommended installation directories on Linux: **/opt/facephi/sdk/selphid/x.x.x.x**
  * To extract the Linux SDK, you must do so on the same Linux server where the symbolic links are created. To do this, use the following command:

    ```bash
    $ tar -xvzf fphi-selphid-sdk-linux64-x.x.x.x.tar.gz
    ```

{% hint style="info" %}
Where "x.x.x.x" is the product version supplied by FacePhi.
{% endhint %}

{% hint style="warning" %}
After installation, the following folders should appear in the selected directory:

* Api: Contains the programming API description.
* Bin: Contains the binary files.
  * Windows: Runtime libraries and applications.
  * Linux: Applications.
* Config: Contains the configuration files.
* Data: Contains the data files required for correct operation at runtime.
* Doc: Contains the EULA documentation and the SDK version file.
* Examples: Contains programming examples.
* Lib: Contains the files and libraries required for the build processes.
  {% endhint %}

### 3.2 SDK Configuration

For the libraries included in the SDK to be available on the system, perform the actions described below:

* **Create the FACEPHI\_SELPHID\_INSTALL\_PATH environment variable**

  The value of this environment variable must contain the selected installation directory from [section 3.1 above](#31-instalación-del-software-development-kit).

  ```bash
  # Windows
  set FACEPHI_SELPHID_INSTALL_PATH=C:\Program Files\FacePhi\Sdk\SelphId\x.x.x.x
  ```

  ```bash
  # Linux
  export FACEPHI_SELPHID_INSTALL_PATH=/opt/facephi/sdk/selphid/x.x.x.x
  ```
* **Add the library directory to the PATH environment variable**

  Once you have created the environment variable above, include the SDK's "bin" (for Windows) or "lib/lib" (for Linux) directory in the system's `PATH` (Windows) or `LD_LIBRARY_PATH` (Linux) environment variable:

  ```bash
  # Windows
  set PATH=%PATH%;%FACEPHI_SELPHID_INSTALL_PATH%\bin
  ```

  ```bash
  # Linux
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$FACEPHI_SELPHID_INSTALL_PATH/lib/lib
  ```

### 3.3 Environment Variables

Several environment variables can be set to configure the SDK's behavior:

* `FACEPHI_SELPHID_FACIAL_LICPATH_KEY` (required). Path to the `license.lic`. E.g. `/opt/facephi/sdk/selphid/x.x.x.x/config/license.lic`.
* `FACEPHI_SELPHID_DEBUGPATH_KEY` (required). Path to the file where the log will be written. E.g. `/opt/facephi/sdk/selphid/x.x.x.x/config/selphidDebug.log`.
* `FACEPHI_SELPHID_USAGEPATH_KEY` (required). Path where the usage data file will be stored. E.g. `/opt/facephi/sdk/selphid/x.x.x.x/config/selphidUsage.db`.
* `FACEPHI_SELPHID_FACIALLIVENESS_PATH_KEY` (required). Path to the `/data` directory in your local file system. E.g. `/opt/facephi/sdk/selphid/x.x.x.x/data`.
* `FACEPHI_SELPHID_FACIALAUTHENTICATION_THRESHOLD` (optional). Similarity value from 0 to 100 used to determine whether an authentication is positive or negative. Default `65`.
* `FACEPHI_SELPHID_FACIALLIVENESS_THRESHOLD` (optional). Threshold from 0 to 100 used to determine whether a liveness operation is positive (Live) or negative (NoLive). Default `50`.
* `FACEPHI_SELPHID_FACIALEXTRACTOR_NUM_THREADS` (optional) 1–8 Number of threads (cores) allocated for extraction and authentication operations. Default `4`.
* `FACEPHI_SELPHID_FACIALLIVENESS_NUM_THREADS` (optional) 1–8 Number of threads (cores) allocated for liveness operations. Default `4`.
* `FACEPHI_SELPHID_FACIALLIVENESS_IAD` (optional) (`enable` or `disable`) Enables the `Inyection Attack Detection` filters for liveness operations. The default is `enable`.
* `FACEPHI_SELPHID_FACIALLIVENESS_DEPTH` (optional) (`partial` or `full`) Specifies the depth of the liveness checks: `partial` (FPAD *Presentation Attack Detection*), `full` (FPAD + FMAD *Manipulation Attack Detection*). The default is `partial`.
* `FACEPHI_SELPHID_GALLERY_REMOVE_METHOD` (optional) (`erase` or `noerase`) Specifies whether gallery items will be completely removed using `SelphIDIdentifier::RemoveWithGalleryIndex()` or marked as invalid without being removed. The default is `erase`.
* `FACEPHI_SELPHID_FUTURE_TIME_ALLOWED` (optional) 0-N Specifies the time, in seconds, for which a token with a future date will be valid. This is a global value that can be overridden per operation using `SelphIDVerifierOptions::SetFutureTimeAllowed()`. The default is 0, which means that all tokens with a future date will be rejected.

## 4. SDK Licensing

To license the SelphID SDK product, perform the actions described below:

### 4.1 Generating machine identifiers

Machine identifiers can be obtained using a terminal and running the following command in the directory containing the utility: `FACEPHI_SELPHID_INSTALL_PATH\bin` (on both Windows and Linux)

{% hint style="warning" %}
Starting with version `6.20.0`, `selphid-license-activator` runs as a standalone application, without requiring environment variables to be configured or depending on SelphID-SDK.
{% endhint %}

```bash
# Windows ( selphid-license-activator.exe )
cd C:\Program Files\FacePhi\Sdk\SelphId\x.x.x.x\bin
selphid-license-activator.exe -hostid SN > hostid.txt
```

```bash
# Linux ( selphid-license-activator.sh )
$ cd /opt/facephi/sdk/selphid/x.x.x.x/bin
$ ./selphid-license-activator -hostid SN > hostid.txt
```

{% hint style="warning" %}
SN is the serial number of the license to be activated, provided by your license provider.

The format of the serial number "SN" is XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX.

Example using the serial number above:

```bash
# Windows ( selphid-license-activator.exe )
selphid-license-activator.exe -hostid XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX > hostid.txt
```

```bash
# Linux ( selphid-license-activator.sh )
$ ./selphid-license-activator -hostid XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX > hostid.txt
```

{% endhint %}

{% hint style="warning" %}
Starting with version `6.15.0`, MAC address-based licensing for network interfaces is enabled. In these cases, the MAC addresses of the interfaces involved in licensing must be declared using the parameter `-addr`.

```bash
# Windows ( selphid-license-activator.exe )
selphid-license-activator.exe -hostid HOSTID -addr "74:04:F1:60:EE:A7" -addr "9C:2D:CD:E8:2A:E5" hostid.txt
```

```bash
# Linux ( selphid-license-activator.sh )
$ ./selphid-license-activator -hostid HOSTID -addr "00:15:5D:01:8C:01" > hostid.txt
```

{% endhint %}

Once the machine identifiers have been obtained, the file **hostid.txt** must be sent to your license provider so that your license (a file with the .lic extension) can be generated.

{% hint style="warning" %}
Starting with Version 6.2.0, it is possible to **activate the license online** . In this case, your license provider will supply you with a file `.lic` without the need to generate machine identifiers (you do not need to run `selphid-license-activator`).
{% endhint %}

### 4.2 License installation

The following steps describe how to install the license:

* **Copy the license to the config directory**

  To install the license, simply copy the file `license.lic` that you receive from your distributor to the `config` directory located in the SDK installation path: `FACEPHI_SELPHID_INSTALL_PATH\config`
* **Configure the license in the selphid.cfg file**

  Once the license file has been copied, set the value of the variable in the file **selphid.cfg** to the path where the license is located:

  ```
  # Windows
  FACEPHI_SELPHID_FACIAL_LICPATH_KEY=C:\Program Files\FacePhi\Sdk\SelphId\x.x.x.x\config\license.lic
  ```

  ```
  # Linux
  FACEPHI_SELPHID_FACIAL_LICPATH_KEY=/opt/facephi/sdk/selphid/x.x.x.x/config/license.lic
  ```

{% hint style="info" %}
The `config` directory is the default directory for installing the license, although it can also be installed in another directory on the server. In that case, you simply need to specify that directory in the configuration file.
{% endhint %}

<br>

{% hint style="warning" %}
It is essential to verify that the values of the following variables are correctly configured with paths that exist in the operating system:

* FACEPHI\_SELPHID\_FACIAL\_LICPATH\_KEY: Path to the file `license.lic`.
* FACEPHI\_SELPHID\_FACIALLIVENESS\_PATH\_KEY: Path to the `/data` directory in the SelphID installation. Required for passive liveness detection.
* FACEPHI\_SELPHID\_USAGEPATH\_KEY: Path to the file where usage statistics are stored.
* FACEPHI\_SELPHID\_DEBUGPATH\_KEY: Path to the file where debug information is stored. If omitted, no debug information will be generated.

You should also check the license expiration date (found in the license file in the "dateEnd" field) to make sure the license is valid and has not expired.
{% endhint %}

### 4.3 License service installation

The SelphID SDK license server is a command-line application that runs on Windows or Linux.

This application serves SelphID licenses to client nodes without a static hostID. However, the server must run on a machine with both a **hostID** and a service port with a static **TCP/UDP** configuration.

Requirements:

* Hardware:
  * Static HostID
  * Static port
* Software:
  * SelphID SDK
* **Running the license service on a Linux terminal**

  Steps to run the license service on a Linux user terminal:

  1. Unzip SelphID SDK. Example:

     ```bash
     $ /opt/fphi-selphid-sdk-linux64_X.X.X
     ```

  2. Copy the license from the server to the server directory with `rw`permissions. Example:

     ```bash
     $ /opt/facephi/fphi-selphid-sdk-linux64_X.X.X/bin
     ```

  3. Export the SelphID SDK library path to `LD_LIBRARY_PATH`. Example:

     ```bash
     $ export \
         LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/facephi/fphi-selphid-sdk-linux64_X.X.X/lib/lib/
     ```

  4. Run the license service application, specifying the port (-port), the path to the server license file (-lic) and, optionally, the path to the license service log (-log).

     <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>The license server must be started in administrator mode.</p><pre class="language-bash"><code class="lang-bash">$ sudo LD_LIBRARY_PATH="$LD_LIBRARY_PATH" ./selphid-license-server -lic license-server.lic -port 15000
     </code></pre></div>

  * Example writing the log to disk and to the console:

    ```bash
    $ cd /opt/facephi/fphi-selphid-sdk-linux64_X.X.X/bin
    $ sudo LD_LIBRARY_PATH="$LD_LIBRARY_PATH" ./selphid-license-server -lic license-server.lic -port 15000 -log /home/user/serverlogs
    ```

    <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>The parameter <code>-log</code> refers to a directory, not a file. This is due to the log rotation implementation.</p></div>

  * Example with the log in the console:

    ```bash
    $ cd /home/user/facephi/fphi-selphid-sdk-linux64_X.X.X/bin
    $ sudo LD_LIBRARY_PATH="$LD_LIBRARY_PATH" ./selphid-license-server -lic license-server.lic -port 15000
    ```

  5. The license server may have been configured for online or offline activation. The licensing mode will be embedded in the `.lic`file. For offline activation, the server will provide an activation key the first time it starts.

     ```bash
     $ sudo LD_LIBRARY_PATH="$LD_LIBRARY_PATH" ./selphid-license-server -lic license-server.lic -port 15000 -log /home/user/serverlogs

     Activation code
     ---------------
     eZPm5npMD2pYwV71uRDcWBcv7wLSoPh/4de763Lo5V7IPYMnhjj03foGyqTu180dT...
     ```

  * This activation key must be sent to your license provider so that your license `.lic` can be updated.
  * The license update will include the activation code for the server, which can then be started without an Internet connection.

    ```bash
    $ sudo LD_LIBRARY_PATH="$LD_LIBRARY_PATH" ./selphid-license-server -lic license-server.lic -port 15000 -log /home/user/serverlogs

    [2023-10-03 15:44:47+02:00] INF Starting floating license server...
    [2023-10-03 15:44:47+02:00] INF Total number of available floating licenses: 20
    [2023-10-03 15:44:47+02:00] INF Listening on port: 15000
    ```

  <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>In the case of <strong>online activation</strong>, the server will start the first time without the <code>.lic</code> file requiring updates.</p></div>
* **Running the license service as a Linux system service**

  Steps to run the license service as a system service on Linux:

  1. Follow steps 1 and 2 of the previous instructions.
  2. Run the application as a system startup application by editing the crontab: `$crontab -e:`
* **Configuring environment variables**

  ```bash
  $ export \
      LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/facephi/fphi-selphid-sdk-linux64_X.X.X/lib/lib/
  ```
* **Run the SelphID license server when the system restarts**

  ```bash
  $ @reboot \\
      /opt \\
      /facephi/fphi-selphid-sdk-linux64_X.X.X/bin/selphid-license-server \\
      -lic /opt/ facephi/fphi-selphid-sdk-linux64_X.X.X/bin/license-server.lic \\
      -port 15000 \\
      -log /opt/facephi/fphi-selphid-sdk-linux64_X.X.X/bin/logFile.txt
  ```

  1. Restart the system. Example: `$sudo shutdown -r now`
  2. Check the log file to confirm that licenses are being served correctly. Example:

     ```bash
     $ cat \\
         /opt/facephi/fphi-selphid-sdk-linux64_X.X.X/bin/logFile.txt

     # Output
     <Date> - Listening: 127.0.0.1:15000
     <Date> - Listening: \\<IP>:15000
     ```
