---
title: "Deploy Forgejo | (Just Updated) Self-Hosted Git Server & GitHub Alternative, Admin Created at Boot"
description: "Forgejo self-hosted Git server with REST API and admin account set at boot"
category: "Other"
url: https://railway.com/deploy/forgejo-or-just-updated-self-hosted-git-
---

# Deploy Forgejo | (Just Updated) Self-Hosted Git Server & GitHub Alternative, Admin Created at Boot

Forgejo self-hosted Git server with REST API and admin account set at boot

**[Deploy Forgejo | (Just Updated) Self-Hosted Git Server & GitHub Alternative, Admin Created at Boot on Railway](https://railway.com/template/forgejo-or-just-updated-self-hosted-git-)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/forgejo-or-just-updated-self-hosted-git-/manifest.json

- **Creator:** SuperSlowSloth
- **Category:** Other

## Template content

### forgejo

- **Image:** ghcr.io/bon5co/forgejo-railway:17.0.1@sha256:10f7de6d2f069cf568c9a6448d05732777e46b54a1d982be8d1c06f095a66c0c
- **Health check:** /api/healthz
- **Public domain:** Yes

## Documentation

# Deploy and Host Forgejo on Railway

**Built for an LLM agent to deploy and use.** The deploy form has no fields to fill: the administrator password and the secret key are generated at deploy time, the administrator account `forgejo-admin` is created at first boot, and every write answers `401` until that password is sent. Forgejo is an open-source self-hosted Git server, a GitHub alternative: repositories over HTTPS, issues, pull requests, packages and a REST API.

## About Hosting Forgejo

This template runs one service, **forgejo** (the web UI, the REST API and git over HTTPS behind one public domain), with a volume mounted at `/data` holding the SQLite database, repositories and attachments. They survive redeploys.

**Locked from boot.** A stock Forgejo container opens the install wizard, which any visitor can complete, and leaves registration open. This template's image ships with the install locked, registration closed and new repositories private. At every boot, once the server answers, it creates the administrator `forgejo-admin` from `FORGEJO_ADMIN_PASSWORD` (32 generated alphanumerics) or resets that account's password to the variable's value. The official Forgejo 17.0.1 image is pinned by digest. SSH is off because Railway cannot give one service both an HTTP healthcheck and a TCP proxy, so clone, push and pull use HTTPS.

### Agent contract

- Public URL: `https://RAILWAY_PUBLIC_DOMAIN` (the generated domain of the `forgejo` service)
- Private URL: `http://forgejo.railway.internal:8080`
- Credentials: the variable `FORGEJO_ADMIN_PASSWORD` on the `forgejo` service; the username is the fixed value `forgejo-admin`
- Auth: HTTP basic (`forgejo-admin:$FORGEJO_ADMIN_PASSWORD`) on every write and every private read; a write without it or with a wrong password answers `401`. Git over HTTPS uses the same pair
- Health: `GET /api/healthz` returns 200 without credentials

```bash
#!/bin/sh
# needs: SITE_URL (public https URL of the forgejo service) and FORGEJO_ADMIN_PASSWORD (its variable); also curl, grep
U="forgejo-admin"; H="Content-Type: application/json"; A="$SITE_URL/api/v1"
curl -s -o /dev/null -w "health: %{http_code}\n" "$SITE_URL/api/healthz"
curl -s -o /dev/null -w "write without key: %{http_code}\n" -X POST -H "$H" -d '{"name":"agent-check"}' "$A/user/repos"
curl -s -o /dev/null -w "write with wrong key: %{http_code}\n" -u "$U:not-the-password-not-the-password" -X POST -H "$H" -d '{"name":"agent-check"}' "$A/user/repos"
curl -s -o /dev/null -w "create repo: %{http_code}\n" -u "$U:$FORGEJO_ADMIN_PASSWORD" -X POST -H "$H" -d '{"name":"agent-check","auto_init":true,"private":true}' "$A/user/repos"
curl -s -o /dev/null -w "add file: %{http_code}\n" -u "$U:$FORGEJO_ADMIN_PASSWORD" -X POST -H "$H" -d '{"content":"aGVsbG8gZnJvbSBhbiBhZ2VudA=="}' "$A/repos/$U/agent-check/contents/hello.txt"
echo "raw read: $(curl -s -u "$U:$FORGEJO_ADMIN_PASSWORD" "$SITE_URL/$U/agent-check/raw/branch/main/hello.txt")"
curl -s -o /dev/null -w "anonymous read of private repo: %{http_code}\n" "$SITE_URL/$U/agent-check/raw/branch/main/hello.txt"
curl -s -o /dev/null -w "delete repo: %{http_code}\n" -u "$U:$FORGEJO_ADMIN_PASSWORD" -X DELETE "$A/repos/$U/agent-check"
curl -s -o /dev/null -w "after delete: %{http_code}\n" -u "$U:$FORGEJO_ADMIN_PASSWORD" "$A/repos/$U/agent-check"
```

A fresh deploy prints `health: 200`, `write without key: 401`, `write with wrong key: 401`, `create repo: 201`, `add file: 201`, `raw read: hello from an agent`, `anonymous read of private repo: 404`, `delete repo: 204` and `after delete: 404`.

## Why Deploy Forgejo 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 Forgejo on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

- **Agent-ready** - no deployer fields, a contract block and one script that proves the refusal without a password, a create, a write, a read and a delete.
- **Locked by default** - no install wizard to hijack, no open sign-up, repositories private.
- **Data survives redeploys** - the database and repositories sit on a volume.
- **Current and pinned** - the official Forgejo 17.0.1 image, pinned by digest.
- **No per-seat pricing** - unlimited repositories and users on your own domain.

## Common Use Cases

- **Self-hosted GitHub alternative** - private repositories, issues and pull requests on infrastructure you control.
- **Agent workspace** - an agent creates a repository, pushes its work and opens a pull request over the REST API.
- **Mirror and backup** - keep a copy of repositories from a hosted forge.
- **Package registry and CI** - host container, npm and other packages next to the code.

## Dependencies for Forgejo Hosting

- The forgejo service with a volume at `/data`, created by the template. A custom domain is optional.

### Deployment Dependencies

- [Forgejo repository](https://codeberg.org/forgejo/forgejo)
- [Official container image](https://codeberg.org/forgejo/forgejo/packages)
- [Wrapper image source](https://github.com/bon5co/forgejo-railway)


## 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) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/forgejo-or-just-updated-self-hosted-git-
