# Install in Single Server mode

Run the Backend as a service in Single Server mode, with TLS and a static list of users.

Other ways: [Install in cloud with Terraform](/install-cloud-terraform/), [Install in custom infrastructure](/install-custom-infrastructure/).

Single Server mode (The mode in which the Backend and all its jobs run on one Linux machine, the server, with no Kubernetes cluster.) is the fastest way to start: for a test or for a small team. To choose the environment, see [Choose an installation path](/plan-choose-installation-path/).

## What you get

In Single Server mode, the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) binary runs on a Linux server, and all its parts stay there: the database, the workspace (The storage where the Backend and all jobs keep the working files of running jobs. The Backend and the jobs use it at the same time. In Kubernetes, it is a network file system; in Single Server mode, it is a folder on the server.), the results and the jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.). When Docker is on the server and turned on for the Backend, each job runs in its own container; otherwise, the jobs run as processes of the system user of the Backend. For the server, see [Requirements of Single Server mode](/plan-single-server-requirements/).

- **Primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.)**: the folder `primary` in the [data folder](/configuration-storage/#data-folder-in-single-server-mode) `/data/platforma`. In this case, the Backend also shares the file system of the server with all users as the host library: see [Host library](/configuration-data-libraries/#host-library), and turn it off when users do not need it. **Workspace**: the folder `work` in the data folder.
- **Sign-in (To show the Backend who you are, with a sign-in provider or a single-user token. The verb is "sign in"; the noun and the adjective are "sign-in".)**: the static list of users (A sign-in provider that is a file with the logins and the password hashes of the users, in the htpasswd format. The Backend reads it again when it changes.) in `/etc/platforma/users.htpasswd`; `admin` is an administrator. When the file changes, the Backend reads it again.
- **Entry point (The way in to the Backend from outside the cluster, a load balancer or an Ingress with a DNS name. It usually ends TLS and sends the traffic to the Backend pod.) and TLS**: the Backend itself listens on all addresses, on port 6345 for the API and on port 6347 for the files of the primary storage (see [Open ports](/security-overview/#open-ports)). It uses TLS from PEM files for the host name that users type in the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.), for example `platforma.example.com`. See [Connect clients](/install-connect-clients/).

**Size.** The size follows the memory and the CPUs (The compute units of a node or of the server, as Kubernetes and the operating system count them. A job asks for a number of CPUs. The cloud quotas call them vCPUs.) of the server. On a server with 256 GiB of memory, up to 7 biggest jobs of samples of 10 M reads run at the same time, or 3 of samples of 100 M reads. A project of 100 such samples then runs in about 34 rounds of the biggest jobs. A server with 128 GiB, the minimum, runs samples of 100 M reads only when they are not very diverse. For the details, see [Size and cost of an analysis](/plan-analysis-size-and-cost/#examples-10-and-100-million-reads-per-sample) and [Memory](/plan-single-server-requirements/#memory).

> **Caution:**
>
> A user who has access to Docker on the server has root rights there, and can read the license key and the master secret: see [Rights in Single Server mode](/plan-permissions/#single-server-mode).

## Before you start

Prepare these items before you start:

- **The server** meets the [Requirements of Single Server mode](/plan-single-server-requirements/): Linux on amd64, the memory, the disk and the network access.
- **Rights.** Root rights on the server, to make the system user and the service. See [Single Server mode](/plan-permissions/#single-server-mode) in Permissions.
- **A host name and a certificate.** The host name that users type in the Desktop App, for example `platforma.example.com`, a DNS record from it to the server, and a certificate for this name with its private key, as PEM files. The computers of the users must reach ports 6345 and 6347 of the server: see [Open ports](/security-overview/#open-ports). For a test without a certificate authority, see [Self-signed certificate](/configuration-domain-and-tls/#self-signed-certificate).
- **The license key.** See [License](/configuration-license/).
- **Tools** on the server: `curl`, `openssl` and `htpasswd` (the package `apache2-utils` or `httpd-tools`). Docker is optional: when you turn it on for the Backend, each job runs in its own container.

The jobs get their software from the registries of MiLaboratories: without Docker as software archives, with Docker as images. When the server cannot reach them, see [Restricted network mode](/plan-single-server-requirements/#restricted-network-mode) and [Software packages and assets](/configuration-registries/#software-packages-and-assets).

## Steps

Run the commands on the server, as a user with `sudo`.

1. **Make the system user of the Backend and its folders.** The data folder `/data/platforma` holds the database, the workspace and the results: put it on the large disk.

   ```sh
   sudo useradd --system --home-dir /data/platforma --shell /usr/sbin/nologin platforma
   sudo mkdir -p /data/platforma /opt/platforma /etc/platforma/tls
   sudo chown platforma:platforma /data/platforma
   ```

   With Docker, also add the user to the group `docker`: `sudo usermod -aG docker platforma`. This gives the user root rights on the server: see [Rights in Single Server mode](/plan-permissions/#single-server-mode).

   To put the parts of the data folder on other disks, or the results into a bucket, see [Storage](/configuration-storage/#data-folder-in-single-server-mode).

2. **Get the Backend.** The archive holds the Backend and the files that it needs next to it: keep them together.

   ```sh
   curl -fL -o /tmp/platforma.tgz https://dl.platforma.bio/software/platforma-backend/pl-linux-amd64.tgz
   sudo tar -xzf /tmp/platforma.tgz -C /opt/platforma
   /opt/platforma/binaries/platforma --version
   ```

   Result: the command shows the version of the Backend.

3. **Put the secret values into files.** The license key goes into an environment file, and the [master secret](/security-secrets/#master-secret) into a file that only the Backend reads. Do not give them as options: other users of the server can see the command line of a process. Keep a copy of the master secret in a safe place: a new master secret signs out all users (see [The secrets of Platforma](/security-secrets/#the-secrets-of-platforma)).

   ```sh
   openssl rand -base64 32 | tr -d '\n' | sudo tee /etc/platforma/master-secret > /dev/null
   sudo chgrp platforma /etc/platforma/master-secret && sudo chmod 640 /etc/platforma/master-secret
   printf 'PL_LICENSE=%s\nPL_MASTER_SECRET_FILE=/etc/platforma/master-secret\n' '<license key>' \
     | sudo tee /etc/platforma/platforma.env > /dev/null
   sudo chmod 600 /etc/platforma/platforma.env
   sudo htpasswd -cB /etc/platforma/users.htpasswd admin   # asks for the password of admin
   sudo chgrp platforma /etc/platforma/users.htpasswd && sudo chmod 640 /etc/platforma/users.htpasswd
   ```

   For other sign-in providers (A configured way for users to sign in to the Backend: single sign-on (SSO), LDAP or a static list of users. One Backend can have more than one.), see [Authentication](/configuration-authentication/), and for the administrators, see [Users and roles](/configuration-users-and-roles/).

4. **Copy the certificate** and its private key.

   ```sh
   sudo cp tls.crt tls.key /etc/platforma/tls/
   sudo chgrp platforma /etc/platforma/tls/tls.key && sudo chmod 640 /etc/platforma/tls/tls.key
   ```

   For a test without a certificate authority, skip this step, and in step 5 replace `--listen-tls …` with `--self-signed-tls --self-signed-tls-domain platforma.example.com`. The Backend then writes the certificate to `/data/platforma/tls/certificate.cer`. Each computer with the Desktop App must trust this certificate: see [Self-signed certificate](/configuration-domain-and-tls/#self-signed-certificate).

5. **Run the Backend as a service.** The service starts the Backend with the server, and starts it again after a failure.

   */etc/systemd/system/platforma.service*

   ```ini
   [Unit]
   Description=Platforma Backend
   After=network-online.target
   Wants=network-online.target


   [Service]
   User=platforma
   Group=platforma
   EnvironmentFile=/etc/platforma/platforma.env
   ExecStart=/opt/platforma/binaries/platforma --main-root /data/platforma \
     --listen-address 0.0.0.0 \
     --listen-tls /etc/platforma/tls/tls.crt,/etc/platforma/tls/tls.key \
     --primary-storage-fs-url https://platforma.example.com:6347 \
     --auth.provider-id=local \
     --auth.provider-type=local=htpasswd \
     "--auth.title=local=Local password" \
     --auth.htpasswd.file=local=/etc/platforma/users.htpasswd \
     --auth.admin-user=local=admin
   Restart=on-failure
   LimitNOFILE=500000


   [Install]
   WantedBy=multi-user.target
   ```

   To run the jobs in Docker containers, add the line `Environment=PL_RUNNER_ENABLE_DOCKER=true` to the section `[Service]`. Without it, the jobs run as processes, also when Docker is on the server.

   ```sh
   sudo systemctl daemon-reload
   sudo systemctl enable --now platforma
   systemctl status platforma
   ```

   The option `--primary-storage-fs-url` gives the data address, where the Desktop App uploads and downloads the files: the host name of the server and port 6347. Without it, the address is `https://0.0.0.0:6347`, and the Desktop App cannot reach it. See [Open ports](/security-overview/#open-ports).

   Result: the service is `active (running)`. The logs of the Backend are in `/data/platforma/log/`. When the license key is not valid, the service also runs, but the log has `License verification failed`, and the Backend does not run jobs: see [License](/configuration-license/).

   To limit the memory and the CPUs of the jobs, see [Jobs and resources](/configuration-jobs-and-resources/#single-server-mode). For a proxy or a corporate certificate authority, see [Proxy and custom CA](/configuration-proxy-and-custom-ca/). For data libraries (A folder or bucket with input data of the company. Users select files from it in the Desktop App. Platforma only reads it.) and the host library, see [Data libraries](/configuration-data-libraries/). For mirrors of the registries, see [Registries](/configuration-registries/).

6. **Check the ports and the certificate**, from a computer of a user:

   ```sh
   openssl s_client -connect platforma.example.com:6345 -servername platforma.example.com \
     -verify_hostname platforma.example.com -verify_return_error -alpn h2 </dev/null >/dev/null 2>&1 \
     && echo "6345: certificate OK"
   openssl s_client -connect platforma.example.com:6347 -servername platforma.example.com \
     -verify_hostname platforma.example.com -verify_return_error </dev/null >/dev/null 2>&1 \
     && echo "6347: certificate OK"
   ```

   Result: `certificate OK` for each port. When a line does not show, the certificate of this port is not valid for the host name: run its `openssl` command again without `>/dev/null 2>&1` to see the error. With a self-signed certificate, or a certificate of a corporate certificate authority that the computer does not trust, add `-CAfile <file of the certificate>` to the command. For the other TLS settings, see [TLS on the Backend](/configuration-domain-and-tls/#tls-on-the-backend).

7. **Verify the installation.** See [Verify the installation](/install-verify/).

8. **Connect the Desktop App** to `platforma.example.com`, port 6345, and sign in as `admin` with the password of the list of users. See [Connect clients](/install-connect-clients/).

## Next

- [Verify the installation](/install-verify/)
- [Authentication](/configuration-authentication/)
- [Backup and restore](/maintain-backup-and-restore/)

Source: https://docs.platforma.bio/install-single-server/
