# Installing the Server

This chapter explains how to install the FIRERPA server. The FIRERPA server is the most crucial component and the fundamental underlying service. You can choose to install it via the APK we provide (supports auto-start on boot), the Magisk module (supports auto-start on boot), or manually. Their installation complexity increases in order.

```{important}
By default, the installed FIRERPA has no authentication enabled, allowing anyone to access any content on the device. If you are deploying using the APK, you can enable authentication in **Settings**. For other installation methods, please refer to the [Server Certificate](./server-certificate.md) chapter to learn how to enable certificates. If you choose not to enable authentication, be sure to use it only within a trusted network; otherwise, it increases the risk of the device being compromised.
```

## Installing via APK

First, we introduce the simplest installation method. This method requires no extra steps; you only need to install our auto-install and auto-start APK. For detailed installation steps, please refer to the [Quick Start](./quick-start.md) chapter.

```{note}
The following content is documentation related to manual deployment, suitable for situations where you need to embed the server into a ROM or manually start the FIRERPA service. If you have already started the server using the APK and have no such requirements, you do not need to read this chapter further.
```

## Getting the Device Architecture

Since FIRERPA supports multiple CPU architectures, downloading an incorrect server version will prevent it from executing properly. Therefore, you need to obtain the device's architecture before installation. You can run the following command:

```bash
getprop ro.product.cpu.abi
```

For modern physical phones, this command typically outputs `arm64-v8a`; for emulators (such as LDPlayer), when creating a new emulator, you can choose a 32-bit or 64-bit Android system, where the 32-bit system corresponds to `x86` and the 64-bit system to `x86_64`; some older Xiaomi models may output `armeabi-v7a`. Remember this output value.

## Service Configuration

Please refer to the [Service Configuration](./properties.md) chapter to learn how to configure service startup items. Relevant configuration details are also covered in the introductions of various features.

## Installing via Magisk

If your device uses Magisk, you can complete the installation in the simplest way, and FIRERPA can **auto-start on boot**. The Magisk version must be ≥ 20.4, and installation is only supported through the **Magisk App**.

Download `lamda-magisk-module.zip` from the [lamda/releases](https://github.com/firerpa/lamda/releases) page and push it to `/sdcard`. Open the Magisk App, navigate to "Modules" → "Install from storage", select `lamda-magisk-module.zip`, and wait a moment.

```{tip}
If any error occurs causing installation failure, it may be because the module zip file is too large. Use compression software to directly open the zip file, delete the server files corresponding to architectures you do not need from the server directory, and then reinstall without extracting and recompressing.
```
After successfully flashing, please restart the device. After reboot, the FIRERPA service will start 30 seconds after boot, not immediately. Please wait 1~2 minutes after boot before attempting to connect to FIRERPA.

If you want the service to automatically set a proxy or connect to FRP forwarding upon startup, please refer to the [Service Configuration](./properties.md) chapter to write the corresponding configuration. Save the configuration in standard **ini** format, rename the file to `properties`, and place it into the `common` folder inside the module zip file `lamda-magisk-module.zip`. To preinstall a service certificate during Magisk module installation, you can generate a PEM certificate as described in the [Server Certificate](./server-certificate.md) chapter, rename it to `lamda.pem`, and also drag it into the module's `common` folder. If you need to preauthorize [Built-in ADB](./built-in-adb.md), write the content of your local `adbkey.pub` file into a file named `adb_keys` and drag it into the `common` folder.

```{attention}
It is recommended to open `lamda-magisk-module.zip` using **compression software**; do not extract and recompress. Be sure to perform operations directly inside the compression software by drag-and-drop, or ensure that the directory hierarchy of files inside the module remains exactly the same, otherwise the module may not function properly.
```

## Manual Installation

Download the latest version of `lamda-server-arm64-v8a.tar.gz` from the release page [lamda/releases](https://github.com/firerpa/lamda/releases), and use the adb push command to push the file to the device's temporary directory `/data/local/tmp`.

```bash
adb push lamda-server-arm64-v8a.tar.gz /data/local/tmp
```

Once done, enter `adb shell`. If the device has root privileges, first run the `su` command to switch users; otherwise, you can directly execute the following commands with the current shell identity:

```bash
INSTALLDIR=$( [ $(id -u) -eq 0 ] && echo /data/ || echo /data/local/tmp )

echo "Server install directory: $INSTALLDIR/server"

tar -C $INSTALLDIR -xzf /data/local/tmp/lamda-server-arm64-v8a.tar.gz
rm /data/local/tmp/lamda-server-arm64-v8a.tar.gz
```

```{attention}
Some older devices may not be able to extract `.tar.gz` files using the built-in `tar` command, so a `busybox` is provided as a supplement; you may need to download this busybox as well. Download `busybox-arm64-v8a` from [lamda/releases/tag/v10.0](https://github.com/firerpa/lamda/releases/tag/v10.0), temporarily push the file to /data/local/tmp, and use `/data/local/tmp/busybox-arm64-v8a tar` for extraction.
```

## Manual Startup

```{attention}
FIRERPA installed via Magisk or the APK will start automatically on boot.
```

```{hint}
There is a chance that remote desktop keeps loading on the first startup. If this happens, first try rebooting the device and restarting the FIRERPA service. If it still cannot be used after waiting for a long time, please report this issue to us.
```

```{hint}
The FIRERPA service supports running as root or as shell. If you need full capabilities, run the server as root.
```

Enter adb shell, and according to the current device status, choose to run the following command as `shell` or `root`. After executing, wait for the command to return; if the output shows `llllaamDaa started`, it means the service started successfully and has entered background mode. You can then safely exit adb shell and access the FIRERPA service. Otherwise, troubleshoot based on the error messages below.

```bash
sh /data/server/bin/launch.sh
```

| Error Output             | Explanation                            |
|--------------------------|----------------------------------------|
| already running          | The service is already running         |
| not run as root/shell    | Please run as root or shell            |
| unsupported sdk          | This Android version is not supported  |
| abi not match            | A tar.gz package of the wrong architecture was used |
| file broken              | File is corrupted, please reinstall    |

## Uninstalling the Service

FIRERPA manages its own data in a very standardized manner and absolutely does not randomly place files in your system. For Magisk installations, simply remove the module in the Magisk app; for APK installations, use the uninstall function within the APK.

```{danger}
Use these features with caution. These directories contain data related to your use of the FIRERPA service. The uninstall operation will completely remove FIRERPA and all data generated by FIRERPA, and this is irreversible.
```

Before uninstalling, please first [shut down the service](./shutdown-reboot.md#shutting-down-the-service) and wait at least 30 seconds to ensure the service exits gracefully.

```bash
rm -rf /data/server /data/usr # /data/local/tmp/usr
```

This will completely remove FIRERPA from your device. It is recommended to reboot the device after execution.