Basic Server Setup and Server Installation

Create a user under which the server will run.

root@server # adduser valheimuser

Create a directory for the server.

root@server # mkdir /opt/valheimserver

Create the install script for the server /opt/valheimserver/install_update.sh

#!/bin/bash cd "$(dirname "$0")"; dir=$(pwd); /usr/games/steamcmd +@sSteamCmdForcePlatformType linux +force_install_dir ${dir} +login anonymous +app_update 896660 -beta public validate +quit;

Change /opt/valheimserver/install_update.sh to be executable.

root@server # chmod +x /opt/valheimserver/install_update.sh

Change the owner of /opt/valheimserver and its contents to valheimuser

root@server # chown -r valheimuser:valheimuser /opt/valheimuser

Execute the script as valheimuser

root@server # sudo -i -u valheimuser /opt/valheimserver/install_update.sh

Configuring the firewall

Open ports 2456 and 2457 in ufw.

root@server # ufw allow 2456/udp && ufw allow 2457/udp

Installing BepInEx

Download BepInEx for Valheim from Thunderstore.io on to your local computer. wget will not work because there is not a direct download to the .zip file.

Create a folder to extract the archive on the server.

you@server $ mkdir /home/you/bepinex

Use scp to copy the file e.g. denikson-BepInExPack_Valheim-5.4.2202.zip to the server.

you@your_computer $ scp /home/you/Downloads/denikson-BepInExPack_Valheim-5.4.2202.zip you@remote:/home/you/bepinex/denikson-BepInExPack_Valheim-5.4.2202.zip

Extract denikson-BepInExPack_Valheim-5.4.2202.zip on the server.

you@server # cd /home/you/bepinex && unzip denikson-BepInExPack_Valheim-5.4.2202.zip

Navigate to the BepInExPack_Valheim which was extracted and copy the files in BepInExPack_Valheim to /opt/valheimserver.

you@server # cd BepInExPack_Valheim && sudo cp -r ./* /opt/valheimserver/

Replace the contents of /opt/valheimserver/start_server_bepinex.sh with the following. Change the name, world, and password variables to suit your server. The password must be five or more characters in length or the server will not start.

#!/bin/sh # BepInEx-specific settings # NOTE: Do not edit unless you know what you are doing! #### export DOORSTOP_ENABLE=TRUE export DOORSTOP_INVOKE_DLL_PATH=./BepInEx/core/BepInEx.Preloader.dll export DOORSTOP_CORLIB_OVERRIDE_PATH=./unstripped_corlib export LD_LIBRARY_PATH="./doorstop_libs:$LD_LIBRARY_PATH" export LD_PRELOAD="libdoorstop_x64.so:$LD_PRELOAD" #### export templdpath=$LD_LIBRARY_PATH export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH export SteamAppID=892970 echo "Starting server PRESS CTRL-C to exit" # Tip: Make a local copy of this script to avoid it being overwritten by steam. # NOTE: Minimum password length is 5 characters & Password cant be in the server name. # NOTE: You need to make sure the ports 2456-2458 is being forwarded to your server through your local router & firewall. name="change_to_your_server_name"; world="change_to_your_world_name"; password="change_to_your_password"; ./valheim_server.x86_64 -name "${name}" -port 2456 -nographics -batchmode -world "${world}" -password "${password}" -public 1 export LD_LIBRARY_PATH=$templdpath

Change /opt/valheimserver/start_server_bepinex.sh to be executable.

root@server # chmod +x /opt/valheimserver/start_server_bepinex.sh

Change the owner of /opt/valheimserver and its contents to valheimuser.

root@server # chown -r valheimuser:valheimuser /opt/valheimuser

Configuring systemd

Create a systemd service file /etc/systemd/system/valheim.service with the following contents.

[Unit] Description=Start the Valheim Server Requires=network-online.target After=network-online.target [Service] Type=simple Restart=always RestartSec=10 User=valheimuser Group=valheimuser WorkingDirectory=/opt/valheimserver/ ExecStart=/opt/valheimserver/start_server_bepinex.sh [Install] WantedBy=multi-user.target

Start the server and enable the service so the Valheim server starts at boot.

root@server # systemctl enable --now valheim.service

Installing Mods on the Server

BepInEx mods contain a plugins folder with varying degrees of capitalization. Mods are installed by copying the mod's files from it's plugins folder into /opt/valheimserver/BepInEx/plugins.

For example, the extracted archive of Equipment and Quick Slots contains a Plugins folder which contains the mod .dll file, EquipmentAndQuickSlots.dll. Copy EquipmentAndQuickSlots.dll into /opt/valheimserver/BepInEx/plugins on the server and the mod will be installed.

Because mods need to be copied from your computer onto the server it can be easier to package up your own plugins folder locally and then scp that to /opt/valheimserver/BepInEx/plugins whenever mods are updated.