Setting up a server
*******************

You set up a server once and then deploy any number of experiments to
it.


Choosing a server
=================

A PsyNet server is a Linux machine (Ubuntu is recommended) that meets
these requirements:

* You can log in over SSH with a key file, without a password.

* The account you log in with can run Docker: either it is in the
  "docker" group, or it has passwordless "sudo" so that Dallinger can
  install Docker and add it to the group when you register the server.

* Ports 80 and 443 are free and reachable from the internet.

* It has a DNS name, and every subdomain of that name resolves to the
  server as well (a wildcard record such as "*.my-
  server.example.org"). Each experiment is served at a subdomain.

A pilot runs on a machine with 2 CPU cores and 8 GB of RAM, such as an
AWS "m7i.large" instance. A live study usually needs at least 4 cores
and 16 GB, such as an "m7i.xlarge"; to size the server for your study,
see Choosing a server size. Allow 5 GB of RAM for each experiment that
runs on the server at the same time.

The usual choices are:

* **An AWS EC2 instance provisioned by Dallinger.** One command
  creates the machine, its DNS records and its registration. You pay
  for the instance while it exists; at the time of writing (October
  2026) an "m7i.xlarge" costs around $0.23 an hour, so a five-hour
  study costs around $1.

* **A virtual machine from any cloud provider**, such as Hetzner,
  Contabo, or AWS configured by hand in the console.

* **A physical machine** run by you or your institution.

A server that Dallinger doesn't provision needs key-based SSH login
and DNS records before you register it; see Manual server setup.

In a lab: Your lab may already run a shared server or a shared AWS
account. Ask your lab administrator which server to use before you set
up a new one, and to confirm that:

* you have access to the lab's GitLab group;

* you can push to the lab's Docker registry, if the lab pushes images
  to one;

* your SSH key is registered wherever the lab requires it, for example
  on GitLab or on the lab's servers;

* you have received the lab's credential files (see below).


Choosing a server size
----------------------

How many participants a server can serve at the same time depends
mostly on its CPU. What matters is the number taking part at the same
moment, not the total: recruitment platforms can send many
participants within minutes of a study opening, so plan for that peak
rather than for the average.

In one test, a simple rating experiment (ten static trials and one
async process) ran on a desktop server with 8 cores, 16 CPU threads
and 32 GB of RAM (AMD Ryzen 7 5800X). With bots working at a realistic
pace, it served up to about 640 at once, with a 95th-percentile
response time of about 180 ms and no errors. That is about 40
participants per CPU thread. At 640 the CPU was the limit: the web
workers used about 9 threads and the database about 3, and with more
bots the server handled fewer requests a second. Memory was not the
limit: the experiment used under 5 GB.

Warning:

  The figures in this section apply to apps deployed with Cloudflare
  ingress, which have their own database server and a larger database
  connection pool. Classic-ingress apps share one database server,
  whose smaller pool caps each app at about 200 participants at a
  time, whatever the server's size: in the same test, the response
  time rose to over 400 ms at 320 bots while most of the CPU sat idle.
  Dallinger 12.4 and earlier have the smaller pool for every app.

A cloud vCPU is one CPU thread, often on a slower core, and most
experiments do more work per page than this one, so as a starting
point plan on 20 to 30 participants at a time per vCPU:

+----------------------+----------------------+----------------------+----------------------+----------------------+
| AWS instance         | vCPUs                | RAM                  | Participants at a    | Price per hour       |
|                      |                      |                      | time                 |                      |
|======================|======================|======================|======================|======================|
| "m7i.large"          | 2                    | 8 GB                 | 40–60                | $0.12                |
+----------------------+----------------------+----------------------+----------------------+----------------------+
| "m7i.xlarge"         | 4                    | 16 GB                | 80–120               | $0.23                |
+----------------------+----------------------+----------------------+----------------------+----------------------+
| "m7i.2xlarge"        | 8                    | 32 GB                | 160–240              | $0.47                |
+----------------------+----------------------+----------------------+----------------------+----------------------+
| "m7i.4xlarge"        | 16                   | 64 GB                | 320–480              | $0.93                |
+----------------------+----------------------+----------------------+----------------------+----------------------+

Prices are on-demand Linux prices in the London region ("eu-west-2")
in October 2026; US regions are about 15% cheaper. See AWS's lists of
instance types and on-demand prices. These figures are only a starting
point. Before a large study, measure your own experiment on the server
you will use (see Testing on a server), and keep the number of
participants taking part at once below the capacity it reports.

Experiments with CPU-heavy async jobs, such as tapping experiments
that analyse recordings with REPP, need extra cores for their worker
processes, about one core for each. One worker process keeps up with
about (session length) / (CPU time per job × jobs per participant)
participants at once; Async workers explains how to estimate this and
how to set "worker_processes".

In experiments where participants wait for each other (see Groups and
barriers in detail), each barrier adds requests, so capacity depends
on how often participants reach one. On the same server, the
"rock_paper_scissors" demo, whose pairs choose a move, wait for each
other and then chat for 30 seconds, served about 560 participants at
once. The same game in groups of eight served about 400. The
"create_rate_sync" demo, whose groups of three pass a barrier after
every five-second page, served about 140.

The server is a small part of a study's cost. 100 participants at
once, paid £9 an hour, cost about £900 an hour, while an "m7i.4xlarge"
that can serve several times as many costs under $1 an hour. A server
that is too small makes pages slow or fail for everyone taking part,
which wastes their time and your payments, so choose a size with room
to spare. Remember to tear the server down afterwards: a forgotten
"m7i.4xlarge" costs about $22 a day.


Configuring your computer
=========================

Deployment settings that apply to all your experiments go in
"~/.dallingerconfig" in your home directory. Create it if it does not
exist:

   touch ~/.dallingerconfig

The file uses INI syntax. Every setting must be inside a section; the
section names ("[SSH]", "[Docker]" and so on) are free to choose.
Write comments on their own lines, because a comment written after a
value becomes part of the value.


SSH key
-------

Dallinger connects to the server with a single private key file, set
as "server_pem". It uses only this key, even if your SSH client has
others, and adds it to your SSH agent while it builds images on the
server, so an "ssh-agent" must be running. If none is, "ssh-add -l"
reports that it cannot connect to the agent; start one with "eval
"$(ssh-agent)"". The key might be your personal key
("~/.ssh/id_ed25519" or "~/.ssh/id_rsa") or a PEM file you received
with the server; keep PEM files in "~/.ssh" and make them readable
only by you:

   chmod 600 ~/.ssh/my-server.pem

Then add the path to "~/.dallingerconfig":

   [SSH]
   server_pem = ~/.ssh/my-server.pem

Dallinger accepts an Ed25519, RSA, or ECDSA key. A DSA key has to be
replaced; see Replacing a DSA key.


Replacing a DSA key
-------------------

A DSA (DSS) private key cannot be converted to Ed25519, RSA, or ECDSA.
Check the file named by "server_pem":

   ssh-keygen -l -f ~/.ssh/my-server.pem

"(DSA)" in that output means the key has to be replaced. Generate a
new key, and do not overwrite the old file yet:

   ssh-keygen -t ed25519 -f ~/.ssh/my-new-server.pem
   chmod 600 ~/.ssh/my-new-server.pem

Install "~/.ssh/my-new-server.pem.pub" on the server while a login
still works. Another authorized key can append it to
"~/.ssh/authorized_keys" for the deploy user:

   ssh -i ~/.ssh/other-key.pem ubuntu@my-server.example.org 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys' < ~/.ssh/my-new-server.pem.pub

A current OpenSSH client cannot log in with the DSA key, because it no
longer offers "ssh-dss". If that key is the only login, paste the new
public key in through the server provider's console. Then point
"server_pem" at "~/.ssh/my-new-server.pem" and confirm it:

   ssh -i ~/.ssh/my-new-server.pem ubuntu@my-server.example.org

If you provision servers with "dallinger ec2 provision", set
"ec2_default_pem" to the new key pair's name as well. The file name
must still match that name, as "~/.ssh/<ec2_default_pem>.pem".
Dallinger imports the key pair into a region when it is missing. An
instance that is already running still needs the public key in its
"authorized_keys".


Docker image name
-----------------

"psynet debug ssh", "psynet deploy ssh" and "psynet performance-test
ssh" build the image on the server and do not push it, so you need
neither "docker_image_base_name" nor a Docker registry account. The
image is named after the app ("--app"). If you do set
"docker_image_base_name", it names the image instead.

A registry is needed only if you push images, for example with "psynet
deploy heroku --docker"; see Docker registries.


Dashboard credentials and contact email
---------------------------------------

Each experiment's dashboard is protected by "dashboard_user" and
"dashboard_password". If you leave the password out, a new random one
is generated for each deployment and saved in its "launch-info.json"
(see Launch information); "dallinger ec2 provision" requires
"dashboard_password" to be set ("dashboard_user" defaults to "admin").

Set "contact_email_on_error" to a real address in
"~/.dallingerconfig": participants see it on error pages, and the
server uses it to obtain HTTPS certificates from Let's Encrypt. Server
commands ("dallinger docker-ssh servers add", "servers upgrade" and
"dallinger ec2 provision") read it only from "~/.dallingerconfig" or
the environment, never from an experiment's "config.txt", because a
server isn't tied to one experiment. They reject placeholders such as
"XXX@gmail.com", the value in PsyNet's experiment template, and
"dallinger ec2 provision" refuses to start without a real address.
"servers add" and "servers upgrade" save an address with the server
and print it with where it came from: the one you pass with "--
contact-email", else one already saved, else "contact_email_on_error".

   [Dashboard]
   dashboard_user = admin
   dashboard_password = choose-a-strong-password

   [Email]
   contact_email_on_error = you@example.org

In a lab: Your lab administrator may provide a ready-made
".dallingerconfig" and PEM key, for example in an encrypted archive in
a private credentials repository. Place ".dallingerconfig" in your
home directory and the PEM file in "~/.ssh", run "chmod 600" on the
PEM file, and check that "server_pem" points to it. The lab's file may
already set "docker_image_base_name", the AWS settings and a shared
security group.


Registering the server
======================

-[ Existing server ]-

Check that you can log in with the key from "server_pem" (replace
"ubuntu" with your username on the server):

   ssh -i ~/.ssh/my-server.pem ubuntu@my-server.example.org

Close the connection with "exit", then register the server:

   dallinger docker-ssh servers add --host my-server.example.org --user ubuntu

This takes a few minutes. If Docker is not installed, Dallinger
installs it, including the Docker Compose plugin, and adds your user
to the "docker" group. With classic ingress (the default), on a server
that Dallinger hasn't set up yet, it then starts the shared services
that experiments use (see Setting up and upgrading the shared
services) and prints the log viewer's password once; note it. The "--
host" value is the name you pass as "--server" in later commands, and
experiments are served at "https://<app>.my-server.example.org".

You can register a server by IP address instead of a name. Then also
pass its public DNS name, for example "--dns-host my-
server.example.org"; see Server names and experiment addresses.

-[ AWS (automatic) ]-

"dallinger ec2 provision" creates an EC2 instance, points a subdomain
of your domain at it and registers it. The instance costs money until
you tear it down. Check the AWS console after each study for instances
you have forgotten.

**AWS credentials.** Create an IAM user with these permissions:

* "AmazonEC2FullAccess"

* "AmazonRoute53FullAccess"

* "AmazonS3FullAccess", only if experiments store data or assets in S3

Anyone who obtains these keys can run up charges on your account, so
keep the permissions this narrow and delete keys you no longer use.
Add the keys to "~/.dallingerconfig". "aws_region" sets the default
region ("us-east-1" if omitted):

   [AWS]
   aws_access_key_id = your-access-key-id
   aws_secret_access_key = your-secret-access-key
   aws_region = us-east-1

**Domain.** Register a domain in Route 53, or host an existing
domain's DNS there, and wait until the registration is complete. Each
server gets a subdomain of it, such as "memory-lab.cool-
psychology.org". Dallinger uses the hosted zone that the name ends
with, choosing the longest match.

**Key pair.** In the EC2 console, create a key pair and download its
PEM file to "~/.ssh" (for example "~/.ssh/cool-psychology.pem"). Set
"ec2_default_pem" to the key pair's name, without path or extension,
and "server_pem" to the file. Dallinger finds the file by this name,
as "~/.ssh/<ec2_default_pem>.pem", so the file name must match the key
pair name. A new instance accepts only this key pair, so "server_pem"
must hold the same private key as that file, without a passphrase;
"dallinger ec2 provision" checks this before it boots an instance.
Keep only one "server_pem" line in "~/.dallingerconfig".

   [EC2]
   ec2_default_pem = cool-psychology
   server_pem = ~/.ssh/cool-psychology.pem

If the key pair does not exist in the region you provision in,
Dallinger imports it there from the local file. AWS does not issue DSA
keys. If "server_pem" is a DSA key you created yourself, replace it as
described in Replacing a DSA key.

**Provision.** List the regions with "dallinger ec2 list regions" and
choose the one closest to your participants. Then run:

   dallinger ec2 provision \
       --name memory-lab \
       --region us-east-1 \
       --dns-host memory-lab.cool-psychology.org \
       --type m7i.xlarge

"--name" labels the instance in AWS and may contain only lowercase
letters, digits and hyphens. "--type" defaults to "m5.xlarge";
"m7i.large" suits a pilot and "m7i.xlarge" a live study. "--storage"
sets the disk size in GB (default 32); increase it if the experiment
keeps many participant uploads on the server with "LocalStorage".

Provisioning takes a few minutes. It also starts the shared services
that experiments use (see Setting up and upgrading the shared
services) and prints the log viewer's password once; note it. The
server is registered twice, under its AWS hostname and under the "--
dns-host" name (here "memory-lab.cool-psychology.org"); pass the "--
dns-host" name as "--server". You can deploy once your computer
resolves the new DNS records, which can take up to about five minutes
(15 if you looked a name up before it existed). Experiments are served
at "https://<app>.memory-lab.cool-psychology.org". If anything fails
after the instance is launched, it keeps running and costs money:
provisioning prints the "dallinger ec2 teardown" command that removes
it and, if the setup had started, the commands that finish it instead.
For the other "ec2" commands and what provisioning does, see AWS
automatic provisioning.

In a lab: Your lab administrator creates the IAM credentials and tells
you the lab's shared domain, key pair and security group
("ec2_default_security_group"). Name servers so that others can tell
who owns them, in the form "name-experiment-version", for example "--
name alice-melody-batch2", and use your own subdomain of the lab
domain, for example "--dns-host alice.<lab-domain>".


Checking the server
===================

List the registered servers, then connect to yours:

   dallinger docker-ssh servers list
   psynet apps ssh --server my-server.example.org

A new server reports "No apps found." To check the whole path, deploy
a pilot of any experiment and open "https://<app>.<server DNS name>"
as described in Running a study. On a server with classic ingress, the
log viewer is at "https://logs.<server DNS name>". Its username is
"dallinger", and its password is the random one printed when the
shared services were set up. On a server set up by an older Dallinger,
it is the dashboard password of the server's first deployment, and
"servers upgrade" keeps it. The server keeps it as "DOZZLE_PASSWORD"
in "~/dallinger/.env.json", and each deployment also saves it as
"logs_password" in its "launch-info.json". To change it, run
"dallinger docker-ssh set-dozzle-password --server <server>". Servers
with Cloudflare ingress have no log viewer (see Cloudflare tunnels
(optional)).


Upgrading an existing server
============================

On a server set up by a Dallinger version without "dallinger docker-
ssh servers upgrade", run that command once, after you update
Dallinger (for an experiment, by updating its PsyNet pin; see Update
PsyNet). Deployments usually keep working without it (see Server is
not set up for this classic-ingress deploy for when they don't), but
the upgrade makes the server's HTTPS certificates persist and applies
current database settings. It also protects the server from older
Dallinger versions. Run it when no classic experiment on the server is
live, because it briefly restarts the shared services:

   dallinger docker-ssh servers upgrade --host my-server.example.org

On a server set up by Dallinger 13.0 or earlier, the upgrade also
moves the shared database from PostgreSQL 12 to 18. While it copies
the databases, it stops every classic app on the server, so run it
when no app has participants. The move normally runs without problems,
but as a precaution, first export the data of the apps you still need
with "psynet export ssh --app <app>" (see Exporting data). On a server
that runs PostgreSQL 18, new or moved, no one may deploy with PsyNet
13 or earlier or with PsyNet 14.0.0rc1 to rc3, which use Dallinger 12
or earlier. Nor may anyone run "servers upgrade" on it with Dallinger
13.0. Any of these can take every classic app on the server offline.
Notify everyone who deploys to the server.

A Cloudflare-ingress app runs its own database, which "servers
upgrade" doesn't move. An app deployed with Dallinger 13.0 or earlier
keeps PostgreSQL 12 when you update it with "--update". To move it,
export its data with "psynet export ssh --app <app>", destroy it with
"psynet destroy ssh", and deploy it again under the same name with "--
archive" (see Deploying from archive).

Moving to PostgreSQL 18 in the Dallinger documentation gives the
details, including how to remove the old database volume afterwards.

The upgrade writes the Let's Encrypt contact email into the server's
"Caddyfile": the one you pass with "--contact-email", else the one
saved with the server, else "contact_email_on_error" from
"~/.dallingerconfig" or the environment. A server registered by an
older Dallinger has no saved email, so a deployment there stops if the
only "contact_email_on_error" it finds is a placeholder such as
"XXX@gmail.com". To save an email without restarting anything, run
"servers add" again; it keeps the server's other saved settings:

   dallinger docker-ssh servers add --host my-server.example.org --contact-email you@example.org

Make sure that everyone who deploys to that server updates Dallinger
too. Older versions can no longer deploy there: unless the SSH user is
"root", their deployments fail with "PermissionError: [Errno 13]
Permission denied" before they change the shared files. An older
deployment without "--app" may first offer to destroy the server's
other experiments. Decline: accepting destroys them, and the
deployment still fails. See Setting up and upgrading the shared
services for what the upgrade changes.


Stopping and removing the server
================================

-[ Existing server ]-

Destroy the apps on the server with "psynet destroy ssh" once you have
exported their data. To forget the server on your computer, run:

   dallinger docker-ssh servers remove --host my-server.example.org

This changes nothing on the server itself.

-[ AWS (automatic) ]-

To pause a multi-day study overnight, stop the instance and start it
again the next day. A stopped instance still incurs a small storage
charge.

   dallinger ec2 stop --name memory-lab --region us-east-1
   dallinger ec2 start --name memory-lab --region us-east-1

Stopping removes the DNS records and starting recreates them, for the
"--dns-host" name saved at provisioning. The AWS hostname changes when
the instance restarts, so keep using the "--dns-host" name as "--
server". The experiments restart with the instance; check that they
work before recruiting again.

When the study is over, export all data, then terminate the instance:

   dallinger ec2 teardown --name memory-lab --region us-east-1

Teardown deletes the instance with every database on it, removes the
DNS records and removes both server registrations. On another
computer, after a provision you finished with the printed "servers
add" commands, or for an instance provisioned by an older Dallinger,
add "--dns-host" with its name to "stop", "start" and "teardown" (see
AWS automatic provisioning). Data you have not exported is lost.
Teardown only finds a running instance, so start a stopped server
first with "dallinger ec2 start". "dallinger ec2 list instances
--running" shows the instances that are still running.
