> For the complete documentation index, see [llms.txt](https://docs.fivemstats.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fivemstats.net/tgiann-fivem-stats-script/installation.md).

# Installation

Install tgiann-fivem-stats-script and connect your server to fivemstats.net.

## Before you start

* FXServer artifact **10488** or newer, on Windows or Linux
* `tgiann-core`, `ox_lib` and `oxmysql`
* For screenshots: `screencapture` or `screenshot-basic` (optional)
* ESX, QB-Core or QBox. The script finds your framework on its own.

## 1. Add the script

Download **tgiann-fivem-stats-script** from your **CFX Portal** account and put the folder in your resources. Keep the folder name as it is.

## 2. Edit server.cfg

```cfg
set sv_enableHttpServer true
set tgiann_stats_secret_key "your-long-random-secret"
add_unsafe_child_process_permission "tgiann-fivem-stats-script"

ensure oxmysql
ensure ox_lib
ensure tgiann-core
ensure screencapture
ensure tgiann-fivem-stats-script
```

* `sv_enableHttpServer true` lets the panel talk to your server. It is required.
* `tgiann_stats_secret_key` is the password of the panel. Use a long random value; the panel can make one for you under [Settings > Secret key](/panel/settings.md#secret-key).
* `add_unsafe_child_process_permission` lets the script start its [media service](/tgiann-fivem-stats-script/media-service.md). FXServer's sandbox blocks programs started by a resource without it. It is required.

{% hint style="danger" %}
Never share the secret key. If it leaks, change it in `server.cfg`, restart and update it in [Settings > Connection](/panel/settings.md#connection).
{% endhint %}

{% hint style="info" %}
Does your `server.cfg` limit who can read `mysql_connection_string` with `add_convar_permission`? Then also add `add_convar_permission tgiann-fivem-stats-script read mysql_connection_string`. Without it player names, jobs, money and [Database Backups](/tgiann-fivem-stats-script/database-backups.md) are off, and the console prints a yellow line about it.
{% endhint %}

## 3. Open the ports

| Port                            | Why                                                         |
| ------------------------------- | ----------------------------------------------------------- |
| Game port `30120` (TCP and UDP) | Already open for players. The panel connects through it too |
| Media port `6174` (TCP)         | Screenshots, videos and backup downloads                    |
| `80` (TCP)                      | The free HTTPS certificate                                  |

How to open them: [Ports and Firewall](/tgiann-fivem-stats-script/ports-and-firewall.md). If your host has a DDoS filter, read [DDoS-Protected Hosts](/tgiann-fivem-stats-script/ports-and-firewall/ddos-protected-hosts.md) too.

## 4. Restart the server

The script starts its media service and, on the first start, imports statistics of older versions. When it is ready the console shows:

```txt
[media] v1.0.0 listening on 0.0.0.0:6174 (https://203.0.113.10:6174, https auto)
[media] https: certificate active for 203.0.113.10
```

A red line instead? See [Common Problems](/tgiann-fivem-stats-script/common-problems.md).

## 5. Add your server in the panel

Open [My Servers](https://www.fivemstats.net/dashboard/my-servers), click **Add a server** and enter your server's IP, the game port (`30120`) and the secret key: [Adding a Server](/panel/adding-a-server.md).

## After the first start

1. Turn on **Back up automatically** on the [Backups](/panel/backups.md) page. Backups are off until you do.
2. Check how long data is kept in [Settings > Game script](/panel/settings.md#game-script).
3. Run `/mediatest` in game as an admin (`group.admin`). A test screenshot shows on the [Media](/panel/media.md) page.
4. Invite your staff: [Members and Permissions](/panel/members-and-permissions.md).

Your game database is only read, never written to. Statistics, logs and files are stored in the `tgiann-media` folder inside the script folder. Keep that folder when you update the script: [Updating from an Older Version](/tgiann-fivem-stats-script/updating-from-an-older-version.md).
