Compare commits

1 Commits
main ... wip

View File

@ -0,0 +1,160 @@
---
title: Setup Gitea on Debian
template: blog
page_dir: /blog/2025/07/setup-gitea-on-debian
---
# Setup Gitea on Debian
I just recently setup a new Gitea server for myself, and I would like to share with y'all on how to do the same
This was done on a fresh Debian 12 cheapo VPS on Linode, so this guide will pretty much apply to any Debian (and likely Ubuntu) system that is more-or-less a stock installation
I did this using <a href="https://gitlab.com/packaging/gitea/" target="_blank">a third-party repository for Gitea</a> that was <a href="https://www.gitea.com/gitea/awesome-gitea/src/branch/main/README.md#user-content-packages/" target="blank">linked from the official site</a>, as I don't care for Docker personally, and with a PostgreSQL database as opposed to something like SQLite, as that's the database I prefer to use when I have to use one (I'm not a big database person either)
Caddy will be used for the webserver as well, as it handles automatic TLS certificate acquisition, and is easy to setup
For clarity's sake, any command that starts with a `#` has to be run either as root or with `sudo`, and any command that starts with `$` can be run as a normal user (neither `#` nor `$` are part of the actual command itself)
We'll also assume `nano` will be used for editing files, but you can use whatever text editor you prefer
We're also going to assume you already have a domain name pointed at the server you are doing this on (we'll use `git.example.net` as a placeholder)
## Overview
1. [Adding a repo for installing Gitea](#adding-a-repo-for-installing-gitea)
2. [Install Gitea, PostgreSQL, and Caddy](#install-gitea-postgresql-and-caddy)
3. [Configure PostgreSQL](#configure-postgresql)
4. [Configure Caddy](#configure-caddy)
5. [Setup Gitea](#setup-gitea)
## Adding a Repo for Installing Gitea
First thing we're gonna need to do, since we're not using something like Docker, or just using the standalone binary, is add the third-party repo for Gitea
First up, we'll download the GPG key for the repo
```
# curl -sL -o /etc/apt/trusted.gpg.d/morph027-gitea.asc https://packaging.gitlab.io/gitea/gpg.key
```
Then, we'll add the repo by creating/editing the `.source` file that will contain the repo's information in `deb822` format
```
# nano /etc/apt/sources.list.d/morph027-gitea.sources
```
```
Types: deb
URIs: https://packaging.gitlab.io/gitea
Suites: gitea
Components: main
Signed-By: /etc/apt/trusted.gpg.d/morph027-gitea.asc
Enabled: yes
```
Now we'll update apt so it can refresh it's list of known packages
```
# apt update
```
## Install Gitea, PostgreSQL, and Caddy
Now for the easiest part, we'll install Gitea, our PostgreSQL database, and our Caddy webserver
```
# apt install gitea postgresql caddy
```
## Configure PostgreSQL
Now for configuring PostgreSQL
First we're gonna edit PostgreSQL's config file
```
# nano /etc/postgresql/15/main/postgresql.conf
```
and go to line 96, and uncomment
```
#password_encryption = scram-sha-256 # scram-sha-256 or md5
```
Next, we're gonna edit
```
# nano /etc/postgresql/15/main/pg_hba.conf
```
and add at the bottom of the file
```
local gitea gitea scram-sha-256
```
Now, we'll restart PostgreSQL
```
# sytemctl restart postgresql
```
Now, to actually setup and configure the database
First, we'll need to run `psql` as the `postgres` user
```
$ sudo -u postgres psql
```
Now, we need to create the "role" (user) that PostgreSQL will use for interfacing with the database, replacing `password` with the password you want to assign it
```
CREATE ROLE gitea WITH LOGIN PASSWORD 'password'
```
Next, the database
```
CREATE DATABASE gitea WITH OWNER gitea TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
```
Now exit `psql`
```
exit
```
## Configure Caddy
We're gonna edit the main Caddyfile and configure it to simply reverse proxy traffic to our new Gitea server
```
# nano /etc/caddy/Caddyfile
```
Comment out/delete the contents of the file and put in
```
git.example.net {
reverse_proxy localhost:3000
}
```
And now we'll restart Caddy
```
# systemctl restart caddy
```
## Setup Gitea