# Set Up Your First FiveM Server

From nothing to a server your friends can join: artifacts, licence key, server.cfg, the port that trips everyone up, and locking it down before you invite anyone.

- Platform: FiveM
- Canonical page: https://devtoolsgg.com/guides/fivem/first-server

This is the shortest path from nothing to a server your friends can join, with
the reasoning behind each step rather than a list of commands to paste.

Budget about forty minutes. Most of it is downloading.

> [!NOTE]
> Everything here applies to **FiveM Legacy**. FiveM for GTAV Enhanced differs
> on a few points and they are called out as they come up.

## What you need first

| Thing | Why |
|---|---|
| A copy of GTA V | Only to play. The server itself does not need one. |
| A Cfx.re account | To create the licence key, free. |
| Windows or Linux | 2 cores and 4 GB of RAM is enough to start. |
| An open port | 30120 by default, TCP **and** UDP. |

That last row is where most first attempts die, so it gets its own section
below.

## 1. Get the server files

The server is called **FXServer**. Download the latest recommended build from
the [Cfx.re artifacts page](https://runtime.fivem.net/artifacts/fivem/) and put
it in its own folder, for example `C:\FXServer\server`.

Keep the server files and your own data in **separate folders**:

```text
C:\FXServer\
    server\          the artifacts, replaced on every update
    server-data\     your resources and your server.cfg
```

The reason is upgrades. When a new artifact comes out you delete `server` and
unpack the new one. If your `resources` folder lives inside it, you have just
deleted your server.

## 2. Get your licence key

Go to [portal.cfx.re](https://portal.cfx.re), sign in, and create a key. It asks
for an IP address: use the machine that will run the server, and pick the
correct type, since a key created for the wrong IP simply refuses to start.

> [!CAUTION]
> The key is a secret. Anyone holding it can run a server as you and get it
> revoked. It belongs in `server.cfg`, and `server.cfg` never goes in a public
> git repository.

## 3. Write server.cfg

This is the file everything else hangs off. Rather than copying someone's and
wondering what half of it does, build one with the
[server.cfg Generator](/fivem/server-cfg): it writes the sections in the right
order, uses convar names checked against the Cfx.re command reference, and
explains each option as you set it.

The parts that matter on a first server:

```cfg
# One line per protocol, both pointing at the same port.
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"

# 32 slots and above need onesync on or legacy; above 64 needs on.
set onesync on

sv_hostname "My First Server"
sv_maxClients 48

# Get this from portal.cfx.re
sv_licenseKey changeme
```

### Load order is not decoration

Resources start in the order they are listed. A resource that depends on
another must come **after** it:

```cfg
ensure oxmysql
ensure ox_lib
ensure es_extended
ensure my_own_script
```

Nearly every "attempted to index a nil value" on a fresh server is a load order
problem, not a broken script.

## 4. Open the port, properly

FiveM needs **TCP and UDP on the same port**. Opening only TCP produces the most
confusing symptom in the whole hobby: the server appears in your own list,
accepts your connection, and then hangs on "Connecting".

Three separate places can block it, and all three usually need doing:

1. **Windows Firewall** or `ufw` on Linux: allow 30120 TCP and UDP inbound.
2. **Your router**, if the machine is at home: forward 30120 TCP and UDP to the
   machine's local IP.
3. **Your host's firewall**, if you rent a VPS. This one is a web panel, not the
   machine, and it is the one people forget.

> [!TIP]
> To check whether it is really the port, have someone try to connect while you
> watch the server console. If nothing at all appears there, the traffic is not
> reaching you and the problem is network, not config.

## 5. Start it

From the `server-data` folder:

```batch
C:\FXServer\server\FXServer.exe +exec server.cfg
```

On Linux:

```bash
bash /home/fivem/server/run.sh +exec server.cfg
```

On **Enhanced** the executable is `cfx-server.exe` instead.

A healthy first start prints a line saying the server is listening, then a
resource list. Two errors are common enough to name:

- *"Could not find licence key"* means `sv_licenseKey` is missing, wrong, or
  bound to another IP.
- *"onesync is not enabled"* with more than 32 slots means `set onesync on` is
  missing.

## 6. Add a framework, or do not

You do not need one. A framework gives you jobs, money, inventory and a
character system; without one you have free roam, which is a perfectly good
place to start.

If you do want one, pick a single ecosystem and stay in it:

| Framework | Character |
|---|---|
| **Qbox** | Actively maintained, modern Lua, built on ox_lib and ox_inventory. |
| **QBCore** | Very large script catalogue, older codebase. |
| **ESX Legacy** | The oldest, still widely used, most third-party scripts target it. |

Mixing them is the single most common way to end up with a server nobody can
debug. Whichever you choose, the [Job Generator](/fivem/job) and the
[Item Generator](/fivem/item) write the correct format for each of the three.

## 7. Lock it down before you invite anyone

A default configuration is not a safe one.

```cfg
# Blocks modified game files. 2 also blocks unknown files.
sv_pureLevel 1

# Controls what clients are allowed to create.
sv_entityLockdown relaxed

# Trainers and menus. Leave this off.
sv_scriptHookAllowed false
```

Then set up admin permissions properly with the
[ACE Permissions Builder](/fivem/permissions) instead of granting `group.admin`
by hand. And before you install a single downloaded resource, read
[how to spot a backdoored script](/guides/fivem/spot-a-backdoor). On a public
server it is a matter of when, not if.

> [!IMPORTANT]
> Do not set `rcon_password` unless you actually use RCON. An unset password is
> one fewer thing that can leak.

## Where to go next

- [fxmanifest.lua Builder](/fivem/fxmanifest) when you write your first resource
- [Resource Scaffolder](/fivem/resource) for a working skeleton with the
  server-side checks already in place
- [Blip Sprites](/fivem/list/blips) and [Vehicle Models](/fivem/list/vehicles),
  the two lists you will keep a tab open for


## How to cite

Set Up Your First FiveM Server, devtoolsgg.com. https://devtoolsgg.com/guides/fivem/first-server
