How to Host Foundry (pt 1)

How to Host Foundry (pt 1)

Part 2 is here.

I was looking for an alternative to paying the guys at roll20 $10 / month - yes, I'm aware there's a $5 tier, but I actually wanted some of the custom features that needed the higher tier - and stumbled into Foundry.

The catch? Setting up your own server may run $5 / month unless you can squeeze it in alongside something else.

The good news - the documentation is solid, and the app is structured in a way that makes it easy to wedge in anywhere you can install and run Node.js, and an Nginx or Apache front end is in place or can be added to add as a reverse proxy.

Further good news - the app is worth every penny of the one-time $50 fee.

Now, if you don't have any technical chops, Forge can help you out by setting up a hosted environment for you, but there are alternatives: if you have moderate technical skills, or an interest in spinning up your own linux instance, this is a simple enough project to use as a learning tool.

Like I said - the good news, is that the documentation is good. The bad news - since there are several ways to run foundry, it's a bit spread out. These methods include running the encapsulated app on your own workstation and letting friends connect on the network, to using the same app, and port forwarding, to host games across the internet. They also provide a node.js client to host games on a linux server, whether a rasberry Pi or spare box at home, or on a hosted VPS. So I'm going to provide a guide to:

  • Set up a virtual server on a host such as Digital Ocean or Dreamhost (or AWS...)
  • DNS settings
  • Access that instance via SSH (from a mac or linux device. Putty for windows works, but a "how to" for that is almost its own article)
  • Install Node
  • Install Foundry
  • Initially set up foundry
  • Install NGinX
  • Configure NginX for using a URL and SSL
  • Make foundry start up automatically using PM2
  • And firewall settings, of course.

Also, you need to buy  a copy of foundry. Demos are limited - I believe both foundry and the forge maintain one - but they also have a 30-day money back policy.

VPS

I'm not going to provide much detail here in terms of specifics - exact layouts of panels, admin interfaces, and such, change. Offerings of images and snapshots change. For our purposes, we need a clean instance of linux that we have nearly full admin access to, not just a typical webhost for Wordpress/php sites. One of the simplest places to set one up is Digital Ocean, but another good one is over at Dreamhost and their DreamCompute service. As useful as the DO prepackaged instances can be, here I prefer the Dreamhost setup, with it's default "ubuntu" user.

This example uses an Ubuntu 20 instance. You will need at least one vCPU, 1GB of RAM, and 20 GB of drive space. When you are done, you should have an instance up and running, with an assigned IP address, which you should be able to access via SSH.

DNS

While foundry allows you to access it directly via IP, it's better to have a name. It's usually easier to speak, and if your IP changes, it's a minute or so of work on the backed to fix, with no need to change anything for anyone else.

Editing DNS is outside of the scope of this article, as every DNS provider (including DO, DH, Godaddy, Microsoft, etc) does it differently. In either case, you likely will create an "A" record for your domain that points to the IP address of the server you created above. If your server has the address 17.156.32.190 , you can set "foundry" to point to the address, such that people typing in foundry.mydomain.com will end up at the address of your new server.

Make note of this domain name. It will be useful, among other things, in the next step.

SSH

Whether DO, DH, or Amazon AWS, these and similar services only give you access to the instance via the command line using SSH. When you set up the instance, you will be asked to provide, create, or specify a key. Instead of logging in with a password for your username, you will instead log in with a key. You can, of course, write out the full SSH command every time, but there is a simpler way.

In your home directory on your mac or linux computer (there's a way to do this in putty on windows too), there will be a hidden directory named .ssh, and inside that, you can find, or create, a file called "config". Depending on the underlying OS, vi may be installed, and you can always use a text editor like BBedit, Sublime, Atom, or Visual Studio Code, but worst case, nano is almost universally available. For example:

nano .ssh/config

If the file does not exist, it will create it, and if/once it exists, it will open it. You may see entries like below, and in either case, add one for your server.

# ---- I often comment here to describe the purpose
# "host" is what you will enter instead of the name or address of the server
host myvpsinstance
# HostName can be an IP or a full domain name
HostName mydomainname.domain
# the username you will connect as. DH ubuntu instances often use ubuntu, DO unfortunately often uses root. 
User ubuntu
# this is where you define that you want to use a key instead of a password
PreferredAuthentications publickey
# ... and provide the path to the key file - I usually provide the full path
IdentityFile /Users/me/.ssh/id_rsa

Now you can type:

ssh myvpsinstance

... instead of specifying every aspect of the connection and key file path.

And yes, you can do this via a bash alias, but I like the cleanliness of keeping ssh connection configs separate from everything else, and in an easier to read format.

Log into your server

This is where you start installing things. Go ahead and log into the server, keeping notes on the domain name and the IP address.

Install Node.JS

There are only two major prerequisites for installing foundry on Ubuntu 20.04, and the first is to install node.js.

sudo apt install -y libssl-dev
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt install -y nodejs

These commands will install the underlying package needed for later setting up SSL in foundry, download the source code for node.js, and install node. You should be able to do this at the root of your default user directory.

Install Foundry

You'll need a directory to put everything into. You can use your home directory (if you're not already there, cd with no options defaults to your home directory, also cd ~) if nothing else is on the server and you are not the "root" user. if you are the root user, you will need to create a different user to switch to and do the installation work under.

Aside: you can find out what directory you are in by typing pwd (present working directory)

At this point, create the directories that foundry will be installed in, and that the data will be housed in (separating the latter makes it more portable).

mkdir foundryvtt
mkdir foundrydata
cd foundryvtt

The last will get you into the directory into which you will download, and then unzip the installation package.

You'll need to run a command similar to the one below:

wget -O foundryvtt.zip "https://foundryvtt.s3.amazonaws.com/releases/0.7.9/foundryvtt-0.7.9.zip?<a-bunch-of-generated-ID-code>"

The part in quotes is a temporary link to the installer files that you obtain by logging in to your foundry account once you've paid and registered.

sudo apt install unzip
unzip foundryvtt.zip

The above commands install the unzip utility and then unpack the foundryvtt.zip file into its current directory. With your present working directory being /home/ubuntu/foundryvtt (aka ~/foundryvtt) you should see the following when you run ls -al or ll:

ubuntu@foundry:~/foundryvtt$ ll
total 293864
drwxrwxr-x 5 ubuntu ubuntu      4096 Mar 23 21:02 ./
drwxr-xr-x 9 ubuntu ubuntu      4096 Mar 23 21:01 ../
-rw-r--r-- 1 ubuntu ubuntu      1060 Dec 19 14:58 LICENSE.electron.txt
-rw-r--r-- 1 ubuntu ubuntu   4710103 Dec 19 14:58 LICENSES.chromium.html
-rwxr-xr-x 1 ubuntu ubuntu   6322128 Dec 19 14:58 chrome-sandbox*
-rw-r--r-- 1 ubuntu ubuntu    179981 Dec 19 14:58 chrome_100_percent.pak
-rw-r--r-- 1 ubuntu ubuntu    321151 Dec 19 14:58 chrome_200_percent.pak
-rwxr-xr-x 1 ubuntu ubuntu 127561112 Dec 19 14:58 foundryvtt*
-rw-rw-r-- 1 ubuntu ubuntu 120938841 Mar 23 21:00 foundryvtt.zip
-rw-r--r-- 1 ubuntu ubuntu  10505952 Dec 19 14:58 icudtl.dat
-rwxr-xr-x 1 ubuntu ubuntu    243992 Dec 19 14:58 libEGL.so*
-rwxr-xr-x 1 ubuntu ubuntu   8948976 Dec 19 14:58 libGLESv2.so*
-rwxr-xr-x 1 ubuntu ubuntu   3103488 Dec 19 14:58 libffmpeg.so*
-rwxr-xr-x 1 ubuntu ubuntu   4488304 Dec 19 14:58 libvk_swiftshader.so*
-rwxr-xr-x 1 ubuntu ubuntu   8483376 Dec 19 14:58 libvulkan.so*
drwxr-xr-x 2 ubuntu ubuntu      4096 Dec 19 14:58 locales/
drwxr-xr-x 3 ubuntu ubuntu      4096 Dec 19 14:58 resources/
-rw-r--r-- 1 ubuntu ubuntu   4835574 Dec 19 14:58 resources.pak
-rw-r--r-- 1 ubuntu ubuntu     50591 Dec 19 14:58 snapshot_blob.bin
drwxr-xr-x 2 ubuntu ubuntu      4096 Dec 19 14:58 swiftshader/
-rw-r--r-- 1 ubuntu ubuntu    170904 Dec 19 14:58 v8_context_snapshot.bin
-rw-r--r-- 1 ubuntu ubuntu       107 Dec 19 14:58 vk_swiftshader_icd.json
ubuntu@foundry:~/foundryvtt$ 

You can now run foundry with:

node resources/app/main.js --dataPath=$HOME/foundrydata

NOTE: the above assumes you're in the foundryvtt directory and created the foundryvtt and foundrydata directories in the home directory. The full path would be /home/ubuntu/foundrydatafoundryvtt/resources/app/main.js, and the full path to foundrydata would be /home/ubuntu/foundrydata

ALSO: you technically don't have to create, and specify on run, a separate and special datapath. There is actually a default path, but it is inside of the foundryvtt directory. The suggested method here is cleaner in the long run.

You'll have to do one more thing to connect to foundry - go into the network security settings for Digital ocean, Dreamhost, or whichever VPS service you are using, and allow access on TCP port 30000. We'll shut it down later after we configure Nginx, but for now this lets us test the install.

At this point, if you connect to your server's IP address on port 30000, or to your domain name (such as http://foundry.mydomain.com:30000 ) you can access the first admin and setup page. The access will not use SSL, and so is completely insecure, but you can enter your license key at this point and set an admin password. It also has to be manually started. In my next post, we will fix all of that.

About Last Redoubt