---
title: "Deploy CTFd (Self-Hosted Capture the Flag Platform)"
description: "Self-hosted CTFd for running capture the flag security competitions."
category: "Other"
url: https://railway.com/deploy/ctfd-self-hosted
---

# Deploy CTFd (Self-Hosted Capture the Flag Platform)

Self-hosted CTFd for running capture the flag security competitions.

**[Deploy CTFd (Self-Hosted Capture the Flag Platform) on Railway](https://railway.com/template/ctfd-self-hosted)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/ctfd-self-hosted/manifest.json

- **Creator:** blueorange
- **Category:** Other

## Template content

### ctfd https://raw.githubusercontent.com/gridalpha/ctfd-railway/main/ctfd-mark.svg

- **Source:** https://github.com/gridalpha/ctfd-railway
- **Health check:** /healthcheck
- **Public domain:** Yes

### MySQL https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/mysql.svg

- **Image:** mysql:9.4
- **Start command:** `docker-entrypoint.sh mysqld --innodb-use-native-aio=0 --disable-log-bin --performance_schema=0 --innodb-buffer-pool-size=1G`

### Redis https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/redis.svg

- **Image:** redis:8.2
- **Start command:** `/bin/sh -c "rm -rf $RAILWAY_VOLUME_MOUNT_PATH/lost+found/ && exec docker-entrypoint.sh redis-server --requirepass $REDIS_PASSWORD --save 60 1 --dir $RAILWAY_VOLUME_MOUNT_PATH"`

## Buckets

- **ctfd-uploads**

## Documentation

# Deploy and Host CTFd on Railway

![CTFd logo](https://raw.githubusercontent.com/CTFd/CTFd/master/CTFd/themes/core/static/img/logo.png)

CTFd is the most widely used open-source platform for running **Capture the Flag** security competitions, with **6,800+ GitHub stars** and years of use at universities, conferences, companies and training programmes. It handles challenges, flags, scoring, the live scoreboard, teams, hints and file downloads. This template runs CTFd on Railway with MySQL, Redis and object storage for challenge files. The setup wizard is already closed and the admin account created, so nobody can take over your event. CTFd's hosted Basic plan is $50–60/month. Your own instance runs for about $12–20/month, and you can scale it up just for event day.

---

## What This Template Deploys

| Service | Purpose |
|---|---|
| **ctfd** | CTFd on gunicorn (4 gevent workers) on port `8000` with a public HTTPS domain: challenges, scoreboard, admin panel and API. |
| **MySQL** | MySQL 9.4 storing users, teams, challenges, solves and settings, on a persistent volume. |
| **Redis** | Cache and session store, so the scoreboard stays fast under load. |
| **Bucket** | A Railway Bucket (`ctfd-uploads`) for challenge files and uploads, served directly to players. |

The app image is a thin layer over the official `ctfd/ctfd` image. It runs database migrations, creates the admin, closes the setup wizard and marks the session cookie `Secure`, then hands over to CTFd's own launcher.

---

## About Hosting CTFd

Running a CTF means a public site that has to survive a burst of hundreds of players hammering the scoreboard the moment the event opens. It needs a real database, a cache, file storage for challenge downloads, correct client IPs for logging and anti-cheat, and HTTPS. Upstream's Docker setup covers most of this, but a fresh install has a public setup wizard: whoever opens the site first becomes the administrator.

This template closes that gap. On first boot, it creates the admin account from your variables and completes setup, so the wizard never appears. Challenge files go to object storage, Redis handles sessions and caching, and the reverse-proxy setting passes players' real IP addresses through Railway's edge. On Railway, you can also give CTFd more CPU and RAM just for the event, then scale back down afterwards.

**Set your admin email.** `PRESET_ADMIN_EMAIL` defaults to `admin@example.com`. Change it in the deploy form (or afterwards in the admin panel) to an address you control. The admin password is generated as `PRESET_ADMIN_PASSWORD`.

Typical cost: **~$12–20/month** on Railway between events, plus extra usage while a big event runs. CTFd's hosted plans start at $50/month billed yearly.

---

## Deploy CTFd in Under 10 Minutes

1. Optionally set `CTF_NAME`, `CTF_DESCRIPTION`, `CTF_USER_MODE` (`users` or `teams`) and `PRESET_ADMIN_EMAIL`, then click **Deploy on Railway**.
2. Wait for the first boot. Migrations and setup run automatically (about 3–5 minutes).
3. Copy `PRESET_ADMIN_PASSWORD` from the ctfd service's Variables tab and sign in as `admin`.
4. Open the **Admin Panel**, create challenges with flags, points, hints and files, and set the start and end times.
5. Share your URL. Players register, solve challenges and watch the live scoreboard.

No setup wizard to race. No manual database setup. No file storage to configure.

---

## Common Use Cases

- **University and school CTFs.** Run security competitions for students and clubs.
- **Conference CTF events.** Host a public competition with a live scoreboard during the event.
- **Corporate security training.** Teach developers and staff with hands-on challenges.
- **Hiring challenges.** Use CTF-style tasks to assess security candidates.
- **Team-based competitions.** Switch to teams mode for squads with shared scores.
- **Self-paced training platforms.** Keep challenges open all year as a practice environment.
- **Self-hosted alternative to CTFd's hosted plans.** The same platform on your own infrastructure.
- **Security meetups and workshops.** Spin up an instance for one evening, then scale it down.

---

## Configuration

| Variable | Required | Description |
|---|---|---|
| `PRESET_ADMIN_NAME` | Optional | `admin`, the admin login name. |
| `PRESET_ADMIN_EMAIL` | ✅ Set | `admin@example.com` by default. Change it to your address. |
| `PRESET_ADMIN_PASSWORD` | 🔐 Auto-generated | Admin password, created on first boot. |
| `CTF_NAME`, `CTF_DESCRIPTION` | Optional | Event name and description, set on first boot only. Change them later in Admin, Config. |
| `CTF_USER_MODE` | Optional | `users` or `teams`, set on first boot only. |
| `SECRET_KEY` | 🔐 Auto-generated | Signs session cookies. Keep it stable, or everyone is signed out. |
| `DATABASE_HOST`, `_PORT`, `_NAME`, `_USER`, `_PASSWORD` | ✅ Auto-injected | MySQL connection over the private network. |
| `REDIS_URL` | ✅ Auto-injected | Redis cache and session store. |
| `UPLOAD_PROVIDER`, `AWS_S3_*` | ✅ Auto-injected | `s3` storage on the Railway Bucket for challenge files. |
| `WORKERS`, `WORKER_CLASS` | Optional | `4` gevent workers. Raise workers for big events. |
| `REVERSE_PROXY` | ✅ Set | Proxy hop settings, so CTFd logs players' real IPs behind Railway's edge. |

**Preparing for a big event.** A few days before, raise the ctfd service's CPU and RAM in Railway, increase `WORKERS`, and load-test the scoreboard. After the event, scale back down to keep costs low.

**Email.** Password resets and confirmation emails need an SMTP or Mailgun setup in Admin, Config. Railway blocks outbound SMTP on the Hobby plan, so use Railway Pro or an HTTP-based mail provider.

---

## CTFd on Railway vs. Alternatives

| | CTFd on Railway | CTFd hosted (ctfd.io) | rCTF (self-hosted) | Hack The Box CTF platform |
|---|---|---|---|---|
| **Monthly cost** | ~$12–20 usage | $50 Basic, $100 Plus (yearly) | Hosting only | Quote-based |
| **Self-hosted** | ✅ Yes | ❌ No | ✅ Yes | ❌ No |
| **Unlimited players** | ✅ Yes | ✅ Yes | ✅ Yes | ⚠️ By contract |
| **Setup wizard secured** | ✅ Closed at boot | ✅ Managed | ⚠️ Manual setup | ✅ Managed |
| **Scale up just for event day** | ✅ Yes | ⚠️ Plan upgrade | ✅ Yes | ⚠️ By contract |
| **Plugins and custom themes** | ✅ Yes | ⚠️ By plan | ⚠️ Limited | ❌ No |
| **License** | ✅ Apache-2.0 | ❌ Hosted service | ✅ BSD-3-Clause | ❌ Proprietary |

rCTF is a lighter alternative, but it's less actively maintained than CTFd.

---

## Dependencies for CTFd Hosting

- Railway account. Hobby works between events; Pro for large events and outbound email.
- Your challenges: descriptions, flags and any files to download.
- Optional: an email provider for password resets and confirmations.

### Deployment Dependencies

- [CTFd on GitHub](https://github.com/CTFd/CTFd): source code and releases
- [CTFd Documentation](https://docs.ctfd.io): admin guides and configuration
- [CTFd Docker image](https://hub.docker.com/r/ctfd/ctfd): the upstream image
- [Railway Volumes Documentation](https://docs.railway.com/volumes): persistence for MySQL and Redis

### Implementation Details

The entrypoint waits for MySQL, runs `flask db upgrade`, then runs a bootstrap script that creates the admin and writes the setup flag last. That flag is its own guard: later boots change nothing, and your edits in the admin panel are never overwritten. A build step adds the `Secure` flag to the session cookie. CTFd then starts through its own launcher with gunicorn and gevent workers.

Challenge files live in the Railway Bucket, so the app container keeps no state and can be redeployed at any time.

---

## Frequently Asked Questions

**What is CTFd?**
An open-source platform for running Capture the Flag competitions: challenges, flags, scoring, a live scoreboard, teams, hints and an admin panel.

**How much does it cost compared to CTFd's hosted plans?**
About $12–20/month on Railway, plus extra usage while you scale up for an event. CTFd's hosted Basic plan is $50/month billed yearly, or $60 monthly.

**Why don't I see the setup wizard?**
This template completes setup on first boot with your admin variables, so the public wizard can't be used to take over the site. Sign in as `admin` with `PRESET_ADMIN_PASSWORD`.

**Do I lose challenges or scores when Railway redeploys?**
No. Users, challenges and solves are in MySQL on its volume, and challenge files are in the Railway Bucket. Redeploys keep everything.

**Can CTFd handle a large event?**
Yes, with more resources. Increase the ctfd service's CPU, RAM and `WORKERS` before the event, and Redis keeps the scoreboard fast.

**Can I switch between users and teams mode later?**
`CTF_USER_MODE` only applies on first boot. You can change the mode later in Admin, Config, but do it before players register, because switching resets participation data.

---

## Why Deploy and Host CTFd on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying CTFd on Railway, you get a secured, production-ready CTF platform with a database, cache and file storage that you can scale up for event day and down afterwards.


## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — Self-hosted virtual tabletop for role-playing games (license required)
- [Double Commander in your browser](https://railway.com/deploy/double-commander-in-your-browser) — The Double Commander file manager in the cloud, from any device

Open this page in a browser: https://railway.com/deploy/ctfd-self-hosted
