Why self-host Gitea on a VPS
Gitea uses barely 200 to 300 MB of RAM at idle, making it one of the most efficient Git forges to self-host. On a VPS, you keep full control of your source code: no data is analyzed by a third party, no arbitrary limit on the number of private repositories or collaborators, and no cost that climbs with your team. For an agency or an independent developer, a single VPS can host all client projects with permissions partitioned by organization. Gitea natively includes CI/CD compatible with GitHub Actions workflows (Gitea Actions), a package registry and a web editor, which covers almost the entire development cycle with no external dependency.
Concrete benefits of a self-hosted Gitea
- Minimal memory footprint: runs comfortably on a 2 GB RAM VPS even with several dozen users.
- Private repositories without per-seat billing or imposed limits, unlike SaaS offerings.
- Gitea Actions built in to run your CI/CD pipelines without an external service.
- Package registry (Docker, npm, Composer, Maven) hosted on the same instance.
- Fine-grained authentication: LDAP, OAuth2, personal access tokens and per-user SSH keys.
- Trivial backup: everything fits in one data volume and a database.
Hardware and software prerequisites
Gitea is very frugal. For a small team (up to 20 users), a VPS with 2 vCPU and 2 GB of RAM is more than enough; count on 4 GB if you enable Gitea Actions with local runners that compile code. Plan for at least 20 to 40 GB of SSD storage depending on the size of your repositories. On the software side: Docker Engine and the Docker Compose plugin installed, a domain name (or a subdomain such as git.yourdomain.com) pointing to the VPS IP via an A record, and port 22 reserved for the server's SSH — Gitea will expose its own SSH on another port to avoid the conflict.
Deploy Gitea with Docker and SSL
Prepare the VPS and Docker
Connect via SSH, update the system then install Docker and the Compose plugin. Create a dedicated directory:
mkdir -p /opt/gitea && cd /opt/gitea. Also create a data volume that will survive container updates.Write the docker-compose.yml
Define two services:
gitea(imagegitea/gitea:1.25) and apostgres:16database. Mount./gitea:/datafor persistence, setUSER_UID/USER_GIDto 1000, and map Gitea's SSH to host port 2222:"2222:22". Leave the HTTP port 3000 internal; it will be served by the reverse proxy.Launch the containers
Run
docker compose up -dthendocker compose logs -f giteato follow the initialization. Check that the connection to PostgreSQL succeeds before continuing.Configure the reverse proxy
With Caddy, a single line is enough:
git.yourdomain.com { reverse_proxy localhost:3000 }. Caddy automatically obtains and renews the Let's Encrypt certificate. With Nginx, create aserverthat proxies tohttp://127.0.0.1:3000and usecertbot --nginxfor SSL.Finalize the web installation
Open
https://git.yourdomain.com, complete the wizard by filling in the HTTPS base URL and the database host (db:5432). SetROOT_URLcorrectly, otherwise the clone links will be wrong. Expand "Optional Settings > Administrator Account Settings", create your admin account there, then submit.Secure repository SSH
Configure your clients to clone via
ssh://[email protected]:2222/..., or add aHostblock in~/.ssh/configto hide the port. Disable public sign-up in the admin if the instance is private.
Gitea Actions: self-hosted CI/CD on your VPS
Gitea Actions is Gitea's native CI/CD engine, compatible with GitHub Actions workflow syntax. It lets you run pipelines directly on your infrastructure, with no dependency on an external service.
To enable it, add to your app.ini:
[actions]
ENABLED = trueThen register an act_runner runner in a separate container on the same VPS. Cap its RAM via mem_limit so that a heavy build does not choke Gitea itself. For heavy pipelines (compilation, integration tests), dedicate a second VPS to the runner instead.
A minimal workflow for a Node.js project goes in .gitea/workflows/ci.yml:
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- run: npm ci
- run: npm testThe runner executes this workflow on every push. You can combine multiple jobs, use version matrices, and share artifacts between steps — exactly like GitHub Actions, but on your own server.
Cap the act_runner container RAM to 2 GB via mem_limit: 2g in your docker-compose.yml if your VPS has 4 GB total. That way, even a build that consumes everything allocated to it still leaves 2 GB for Gitea — enough to keep serving pushes and pull requests during compilation. For builds that produce large artifacts (Docker images, binaries), add a separate volume mounted at /home/runner/work to avoid filling Gitea's main data volume.
Gitea or Forgejo in 2026: which one to choose?
Scroll the table
| Criterion | Gitea 1.25 | Forgejo v16 |
|---|---|---|
| Governance | Commercial company (Gitea Ltd) | Non-profit association (Codeberg e.V.) |
| License | MIT | MIT — 100% free software, no enterprise edition |
| Recommended by Awesome-Selfhosted | No (removed in 2022) | Yes — default recommendation since 2024 |
| ActivityPub federation | Not planned | Rolling out since Forgejo v7 (April 2024), GA in v16 |
| Gitea API compatibility | Reference | Compatible: same API, same webhooks, same data format |
| Security — public audits | Rare | Code audits published by the Codeberg community |
| Community roadmap | Driven by Gitea Ltd | Open governance, public RFCs, contributor voting |
| Migration from Gitea | N/A | No data loss: same database schema and same volume format |
Migrate from Gitea to Forgejo
Back up your Gitea instance
Before anything, create a full dump:
docker exec -u git gitea gitea admin dump -c /data/gitea/conf/app.ini. Retrieve the generated archive outside the container and verify that the./giteavolume is included in your VPS snapshot.Check version compatibility
Forgejo v16 supports migration from Gitea 1.20 and later. If your instance is running an older version, first upgrade to Gitea 1.21 or 1.22 via
docker compose pull && docker compose up -d, then verify there are no errors in the logs before proceeding.Replace the Docker image
In your
docker-compose.yml, replaceimage: gitea/gitea:latestwithimage: codeberg.org/forgejo/forgejo:latest. The data volume (./gitea:/data) and the PostgreSQL database remain unchanged — Forgejo reads the same schema and the sameapp.ini.Restart and let it migrate
Run
docker compose pull && docker compose up -d. Forgejo automatically applies the necessary schema migrations at startup. Followdocker compose logs -f forgejountil the message indicating that the HTTP server is listening on port 3000.Regenerate SSH keys
As with any upgrade that changes the binary referenced in
authorized_keys, regenerate the entries:docker exec -u git forgejo forgejo admin regenerate keys. Then verify that agit cloneover SSH succeeds from a client machine.Test and validate
Open the web interface, check repositories, webhooks, and Forgejo Actions runners.
act_runnerrunners registered under Gitea are compatible — reconnect them to the new registration token if the key has changed.
Forgejo v16: key highlights (July 2026)
Forgejo v16.0.0 brings ActivityPub federation to general availability for issues and pull requests: an issue opened on one Forgejo instance can receive comments from users on another instance, without a shared account. The release also includes an instance-level secrets manager (AES-256 encryption at rest), a new code search engine based on the Bleve v2 index with regex support, and significant improvements to the background task scheduler. On the security front, API tokens are now hashed in the database (bcrypt) instead of stored in plaintext — an automatic migration at startup converts existing tokens.
Daily administration: webhooks, repositories and orphan cleanup
Once Gitea is in production, a few maintenance operations come up regularly.
Managing webhooks. Gitea logs the history of every delivery in "Repository Settings → Webhooks → Recent Deliveries". A failed webhook (timeout, HTTP 5xx error) can be replayed manually from that history. If your runners run on the same private network as Gitea, add their IP ranges to ALLOWED_HOST_LIST in the [webhook] section of app.ini — otherwise calls to localhost are blocked by default since Gitea 1.20.
Purging orphaned repositories. A repository deleted through the interface leaves its Git data (objects/) on disk until the next background task run. Force an immediate pass from the admin: "Site Administration → Background Tasks → Run: Purge Deleted Repositories". The freed space only becomes visible after docker exec -u git gitea gitea admin storage --remove-unlisted.
Storage quota per organization. For multi-tenant instances, set a repository quota per organization in app.ini under [repository]: MAX_CREATION_LIMIT = 50. This prevents an account from creating hundreds of repositories unmonitored and filling the data volume.
Advanced troubleshooting: SSH and HTTPS cloning
Permission denied (publickey) after an upgrade. The binary referenced in authorized_keys has changed path (verified in 1.27). The Gitea service responds normally over HTTPS, which masks the problem. Fix with: docker exec -u git gitea gitea admin regenerate keys. Verify that a git clone over SSH succeeds before declaring the upgrade complete.
Timeout or SSL error during HTTPS clone. Three common causes: the ROOT_URL in app.ini does not match the actual HTTPS domain (broken links + possible redirect loop), the reverse proxy does not forward the X-Forwarded-Proto: https header (Gitea then generates HTTP URLs), or the Let's Encrypt certificate has expired (Caddy and certbot renew it automatically, but only if DNS still points to the VPS). Check ROOT_URL first: it is the most common cause after a domain migration.
Slow or stalling SSH clone. The SSH upload-pack uses the same Git process as web operations. If your act_runner is using all available CPU cores during a build, Git operations may end up waiting for CPU. Add cpus: '1.5' to the runner in the compose to reserve cores without starving it completely.
Database migration failed: column already exists. The database received a partial migration (stopped mid-upgrade). Restore the dump taken before the upgrade, start from a clean volume, then restart.
Upgrading to Gitea 1.27 without losing SSH access
Version 1.27 changes the internal path of the gitea binary referenced inside authorized_keys. During the upgrade, existing entries still point to the old path: any clone or push over SSH silently fails with Permission denied (publickey), without any server-side error message pointing to the upgrade. The Gitea service responds normally over HTTPS, which masks the problem. After every upgrade to 1.27 (or to any version that changes this path), run inside the container: docker exec -u git gitea gitea admin regenerate keys. The command rewrites all authorized_keys entries with the correct binary path. Verify that a git clone over SSH succeeds before declaring the upgrade complete.
JWT_SECRET_URI and JWT_SECRET must not coexist in app.ini. If both keys are present, Gitea or Forgejo loads one or the other depending on read order, silently invalidating all OAuth2 and Actions tokens issued before the upgrade. Users see intermittent authentication errors with no message pointing to app.ini as the cause. Choose one mechanism: JWT_SECRET (plaintext value) or JWT_SECRET_URI (path to a secret file), then remove the other. Restart the container after the change.
Going further: Forgejo and advanced CI/CD
If you want to push automation around your Git forge further, the article Host Forgejo on your VPS covers setting up a Forgejo instance with dedicated Actions runners, configuring the built-in OCI registry, and security hardening (fail2ban, IP range restrictions). For teams wanting a complete continuous deployment pipeline, it is the natural complement to this guide.
The official documentation
For advanced configuration and options specific to the tool, refer to the official Gitea documentation or the Forgejo documentation. This guide covers going live on a VPS and migration; the vendor docs remain the reference for fine-tuning and specific use cases.