Skip to content

How to Set Up Forgejo on a Linux Server – Your Own Git Server for Repositories, Mirrors, and Actions

Set up Forgejo on your Linux server: use the One-Click App with HTTPS and an SSH port, or install it manually with Docker Compose. Includes admin setup, database and runner variants, cloning over HTTPS and SSH, GitHub mirrors, backups, and Forgejo Actions.

27 November 202613 min read3 Views0 helpful

Introduction

Forgejo is a self-hosted Git service. Use it to manage repositories in your browser, work with issues and pull requests, use wikis, releases, and package management, and automate tests or builds with Forgejo Actions. Its interface is reminiscent of GitHub, but your data stays on your own server. This guide shows you two ways to get started: the easy way, as a One-Click App that makes Forgejo available over HTTPS in just a few clicks, and the manual installation with Docker Compose. After that, you'll create your first repository, clone it over HTTPS or SSH, and, if needed, mirror projects from GitHub.

When Forgejo on a VPS makes sense

Running your own Git server with Forgejo is worthwhile if:

  • You don't want your code hosted by a third-party provider, for example for private projects, customer projects, or configuration files.
  • You want to bring a small team or multiple projects together, with users, organizations, and permissions for each repository.
  • You want to keep a copy of your GitHub or GitLab projects: Forgejo can import repositories and keep mirrors up to date automatically.
  • Free software and community-led development matter to you. Forgejo is developed under the umbrella of the non-profit organization Codeberg e.V.

Forgejo is less suitable if you're looking for a complete DevOps platform with security scans and large CI/CD pipelines. GitLab is better suited to that, but requires significantly more memory. See Install GitLab.

Forgejo or Gitea?

Forgejo started as a fork of Gitea in October 2022. The two are very similar in everyday use; even Forgejo's internal data directory is still called gitea.

ForgejoGitea
OriginFork of Gitea, developed under the umbrella of the non-profit organization Codeberg e.V.Independent project, originally a fork of Gogs
User experienceVery similar to GiteaVery similar to GitHub
Resource requirementsLowLow
CI/CDForgejo Actions with its own runnerGitea Actions with its own runner
One-Click App8 variants, including one with a preconfigured runner4 variants, runner available as a separate app

Both work well for running your own small Git server. If you prefer Gitea, see the Install Gitea guide. According to the Forgejo documentation, you can migrate from Gitea up to version 1.22 in two steps via Forgejo 10.

The easy way: Forgejo as a One-Click App

The fastest way to get Forgejo is through the One-Click Apps on your VPS. The app is accessible directly over HTTPS using a domain, so you don't need a reverse proxy or certificate. The app also makes port 22222 available for git clone over SSH.

Which variant should you choose?

The app catalog offers Forgejo in eight variants. They differ in their database and whether they include a runner for Forgejo Actions:

VariantDatabaseRunner
ForgejoSQLite, a single file in the data volumeNo
Forgejo with PostgreSQLPostgreSQL 16No
Forgejo with MariaDBMariaDB 11No
Forgejo with MySQLMySQL 8No
Forgejo with Runner (also available with PostgreSQL, MariaDB, or MySQL)As aboveYes

The Forgejo variant with SQLite is enough for you or a small team. If you expect many users and repositories, or prefer a dedicated database, choose Forgejo with PostgreSQL. To run workflows with Forgejo Actions directly on the server, choose a with Runner variant (see below). You can't easily switch variants later, so choose one before installing.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Set up One-Click Apps for instructions.
  • Sufficient resources: In our test, Forgejo with SQLite used around 250 MB of memory while idle. Allow for significantly more if you're using a database, many repositories, or a runner, since the runner starts separate containers for each job.

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
  2. Search the app catalog for Forgejo, choose the variant you want, and click Install app.
  3. Use a custom subdomain or zap.cloud is already selected, with a randomly generated name. Leave it selected or enter your own name: Forgejo will be accessible over HTTPS at this domain and will use it for HTTPS and SSH clone URLs.
  4. Under App configuration, you'll find only optional fields, which you can leave as they are: FORGEJO_SSH_PORT (default 22222), FORGEJO__migrations__ALLOWED_DOMAINS (empty means migrations are allowed from all addresses), and FORGEJO__migrations__ALLOW_LOCALNETWORKS (default false). The app generates the database credentials itself.
  5. Click Queue installation. After one to two minutes, Forgejo will appear online on the app card. Under Connection, the card also shows the IP address with SSH port 22222.

Initial setup and admin account

The variants without a runner don't come with preset login credentials. The first time you open Forgejo, you'll see the Initial configuration page. Whoever submits it first sets up Forgejo and creates the administrator account.

Warning

Open Forgejo right after installation Until you complete the initial setup, anyone who knows the address can open the Initial configuration page. Open the app's Access link as soon as the app is online.

  1. Open the app's Access link.
  2. Leave the database fields at the top unchanged. The Forgejo variant shows SQLite3; the database variants have their connection details configured by the app.
  3. Under General settings, check the prefilled values: Server domain is your domain, SSH server port is set to 22222, and Base URL is set to https:// followed by your domain. Leave these values as they are.
  4. Disable self-registration is already checked. This means only administrators can create new accounts. Leave it checked if you don't want to run a public instance.
  5. Expand Administrator account settings and enter a username, email address, and long password.
  6. Click Install Forgejo. After a few seconds, you'll be signed in as the administrator.

If you leave Administrator account settings empty, the first account registered afterward becomes the administrator. The settings are stored in /data/gitea/conf/app.ini in the data volume. Unlike Gitea, Forgejo's SSH clone URLs are correct out of the box: in our test, they looked like ssh://git@git.example.com:22222/USER/REPO.git without any additional configuration.

Info

SSH port 22222 If you use your own firewall on the server, allow port 22222/tcp. Only one app per VPS can use this port. If you also install Gitea or a second Forgejo instance, enter a different value for FORGEJO_SSH_PORT under App configuration for one of them.

Variants with a runner

According to the app recipe, the initial setup is already complete for with Runner variants. The app creates the administrator account automatically. You can find the username and password in the app settings (gear icon) under App environment > Automatically generated values. The app also starts a Forgejo Runner in its own Docker environment and registers it with Forgejo automatically. In these variants, new repositories initially show only Code and Actions. You can enable issues, pull requests, or the wiki in the repository under Settings > Units.

Updates and backups

Update Forgejo in the app settings (gear icon) under App update. Click Check for updates, then install a new version with Apply update. If the app says it's up to date, there's no newer version in the app catalog yet. The app uses Forgejo 17.

Repositories, users, and settings are stored in Docker volumes and are preserved during updates. However, a volume is not a backup. Forgejo provides the forgejo dump command, which packages repositories, the database, and the configuration into a ZIP file. Run this over SSH on your VPS:

Code
C=$(docker ps --format '{{.Names}}' | grep '^forgejo-')
docker exec -u git -w /tmp $C bash -c 'forgejo dump -c /data/gitea/conf/app.ini'
docker exec $C sh -c 'ls /tmp/forgejo-dump-*.zip'

Copy the displayed file to the server with docker cp $C:/tmp/FILENAME.zip ., then transfer it from there to your computer over SFTP. The Forgejo documentation strongly recommends not using Forgejo during a backup. At a minimum, make sure nobody pushes during this time so the repositories and database remain in sync.

Manual installation

The rest of this guide covers the manual installation of Forgejo with Docker Compose, following the official Forgejo documentation. This is useful, for example, if you don't use One-Click Apps on your server or want to manage everything yourself.

Requirements

  • A Linux VPS running Debian or Ubuntu, with SSH access. See First access via SSH.
  • Docker and Docker Compose. See Install Docker. Check the installation with docker --version and docker compose version.
  • For HTTPS: a domain or subdomain with an A record pointing to your VPS's IP address (e.g., git.example.com).
ResourceMinimumRecommended
CPU1 core2 cores
RAM512 MB1 GB or more
StorageSystem, images, and your repositoriesAdditional space for growth and backups

Forgejo doesn't specify fixed minimum requirements in its documentation. The table is based on our test, where Forgejo with SQLite used around 250 MB of memory while idle. Allow for more if you're running a dedicated database or a runner on the same server.

Prepare the firewall

Forgejo uses port 3000 for the web interface and port 22 inside the container for SSH. The web interface is accessed through the reverse proxy, so you don't need to open port 3000. As in the Forgejo documentation, we'll use port 222 on the server for SSH, because port 22 is already used for the server's SSH access. With ufw, allow only what you need:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 222/tcp
ufw enable
Warning

Docker bypasses ufw Ports published by Docker with ports: are accessible from the internet even if they're blocked by ufw. So, as in the Compose file below, bind the web interface to 127.0.0.1 only. See Firewall management on Linux for more about firewalls.

Install with Docker Compose

Create a directory for Forgejo. According to the documentation, the data directory must belong to the user Forgejo runs as; otherwise, the container may not start:

Code
mkdir -p /opt/forgejo/forgejo
chown 1000:1000 /opt/forgejo/forgejo
cd /opt/forgejo

Create the Compose file with nano docker-compose.yml. It follows the Forgejo documentation's example using SQLite:

Code
networks:
  forgejo:
    external: false

services:
  server:
    image: codeberg.org/forgejo/forgejo:17
    container_name: forgejo
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - FORGEJO__server__DOMAIN=git.example.com
      - FORGEJO__server__ROOT_URL=https://git.example.com/
      - FORGEJO__server__SSH_DOMAIN=git.example.com
      - FORGEJO__server__SSH_PORT=222
    restart: always
    networks:
      - forgejo
    volumes:
      - ./forgejo:/data
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "127.0.0.1:3000:3000"
      - "222:22"

Here's what the entries mean:

  • image: Forgejo major version 17, as used by the One-Click App. The 17 tag always points to the latest update within this version. You'll need to upgrade to the next major version yourself.
  • USER_UID and USER_GID: Forgejo creates its files in the forgejo directory using this user ID and group ID.
  • FORGEJO__server__...: The public address, name, and port used in clone URLs. Replace git.example.com with your domain. Use the pattern FORGEJO__<section>__<key> to set any option from app.ini.
  • 127.0.0.1:3000:3000: The web interface is accessible only from the server itself; external access goes through the reverse proxy.
  • 222:22: Server port 222 forwards to the SSH service inside the container.

Without any additional settings, Forgejo uses SQLite. To use PostgreSQL or MySQL, add a db service and the FORGEJO__database__DB_TYPE, HOST, NAME, USER, and PASSWD lines, following the database example in the documentation.

Start the container:

Code
docker compose up -d

Check whether it's running with docker compose ps and view the logs with docker compose logs -f.

First access

Because the web interface listens only on 127.0.0.1, it's best to set up the reverse proxy in the next section first, then access Forgejo at https://git.example.com. Alternatively, open the page using an SSH tunnel from your computer:

Code
ssh -L 3000:localhost:3000 root@SERVER_IP

Replace SERVER_IP with your VPS's IP address and open http://localhost:3000 in your browser. The Initial configuration page will appear. Check that your domain is under Server domain, 222 is under SSH server port, and your HTTPS address is under Base URL. Keep Disable self-registration checked, create your admin account under Administrator account settings, and click Install Forgejo.

Access over HTTPS through a reverse proxy

To access Forgejo externally, put a reverse proxy with a valid certificate in front of it. For the basics, see Set up a reverse proxy with nginx and Create an SSL certificate (Let's Encrypt). Here's an nginx server block based on the example in the Forgejo documentation:

Code
server {
    listen 80;
    listen [::]:80;
    server_name git.example.com;
    merge_slashes off;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Connection $http_connection;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        client_max_body_size 512M;
    }
}

Forgejo needs merge_slashes off for URLs containing encoded slashes. client_max_body_size allows larger uploads; otherwise, nginx will stop them with the error “413 Request Entity Too Large.” Then obtain the certificate with certbot --nginx -d git.example.com. Certbot adds HTTPS and redirects HTTP to the server block. Find more tips on securing your server in Linux security tips.

Back up your data

All data is stored in the forgejo directory alongside the Compose file; with SQLite, the database is there too. The forgejo/gitea/conf/app.ini file is also important: it contains keys that Forgejo needs to read stored secrets, such as two-factor authentication settings or Actions secrets, after a restore. The documentation strongly recommends stopping Forgejo before creating a backup:

Code
cd /opt/forgejo
docker compose stop
tar -czf /root/forgejo-backup-$(date +%F).tar.gz forgejo docker-compose.yml
docker compose start

Then copy the archive to another storage location. If you use PostgreSQL or MySQL, also back up the database with its own tools, such as pg_dump.

Update Forgejo

To install updates within major version 17, run:

Code
cd /opt/forgejo
docker compose pull
docker compose up -d

To upgrade to a new major version, for example from 17 to 18, the Forgejo documentation requires a full backup. First, read the upgrade guide and the notes for the relevant version. Then update the tag in docker-compose.yml and restart as above. Afterward, check that everything is working:

Code
docker exec -u git forgejo forgejo doctor check --all

Remove old images with docker image prune.

Create, clone, and mirror repositories

After setup, create your first repository by clicking the plus icon in the top-right corner > New repository. Select Initialize repository to have Forgejo create a README file so you can clone the repository right away.

Clone over HTTPS

You can find the clone URL in the repository by clicking HTTPS in the top-right corner:

Code
git clone https://git.example.com/USER/REPO.git

Git will ask for your Forgejo username and password. If you've enabled two-factor authentication, use an access token generated under Settings > Applications instead of your password.

Clone over SSH

To use SSH, add your public key once under Settings > SSH / GPG keys > Add key. See Create an SSH key for instructions on generating a key pair. You can find the address by clicking SSH:

Code
git clone ssh://git@git.example.com:22222/USER/REPO.git

The port is 22222 for the One-Click App and 222 for a manual installation. In our test, cloning and pushing worked both ways.

Import or mirror projects from GitHub

Use the plus icon > New migration to import repositories from GitHub, GitLab, Gitea, Forgejo, and other services. Select This repository will be a mirror to have Forgejo automatically fetch updates from the source on a regular basis. In the repository, click Synchronize now under Settings to sync immediately. In our test, we were able to mirror a public GitHub repository without entering anything else. For private repositories, provide an access token from the source. You can't turn an existing repository into a mirror afterward. Conversely, Forgejo can also push to another destination under Settings > Repository, in the Mirror settings section.

Forgejo Actions

Create workflows with Forgejo Actions in the repository's .forgejo/workflows directory, similar to GitHub Actions. In our test, new repositories showed the Actions tab immediately. However, workflows aren't run by Forgejo itself; they're run by a Forgejo Runner:

  • As a One-Click App: Choose a with Runner variant. According to the app recipe, the runner registers itself and provides the docker (Node.js 22), ubuntu-latest, and ubuntu-22.04 labels.
  • Manual installation: Install the runner by following the runner documentation. You can find a registration token in the administration area under Admin settings > Actions > Runners (at /admin/actions/runners).

A runner executes third-party code. The Forgejo documentation explicitly warns about this risk, so only use runners for repositories you trust. Without a connected runner, workflows stay in the queue.

Limitations

  • Storage space: Repositories, releases, LFS files, and packages use storage on your VPS. If you run out of space, increase it in the Manage plan tab for your VPS.
  • Email: Without a mail server, Forgejo can't send notifications or password reset links. Enter the details during initial setup under Email settings, or later using FORGEJO__mailer__ variables.
  • Database variant: You can't switch the One-Click App from SQLite to PostgreSQL with a single click.

Conclusion

You've set up Forgejo on your VPS, created an admin account, and learned how to clone repositories over HTTPS and SSH, mirror projects from GitHub, and back up your data. You now have your own lightweight Git server that runs well even on small servers.

Prefer not to deal with Docker manually? Use the easy One-Click App option described above under “The easy way: Forgejo as a One-Click App.”

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the fastest option: Forgejo is available over HTTPS in just a few clicks, SSH for git clone is accessible on port 22222, and you can install updates under App update in the ZapX dashboard. Manual installation with Docker Compose is a good choice if you don't use One-Click Apps on your server or want to configure the ports, database, and reverse proxy yourself.
Forgejo started as a fork of Gitea in 2022 and is developed under the umbrella of the non-profit organization Codeberg e.V. The two are very similar in everyday use, are both lightweight, and include Actions with their own runner. Both are available as One-Click Apps; Forgejo also has variants with a preconfigured runner.
The variants without a runner don't come with preset login credentials. The first time you open Forgejo, you'll see the Initial configuration page, where you can create your admin account under Administrator account settings. Open Forgejo right after installation. With the with Runner variants, the app creates the admin account automatically. You'll find the username and password in the app settings under App environment > Automatically generated values.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.