Install Forgejo

Table of Contents
Git #
Install git:
apt install git git-lfs gpg
User #
Create the user for Forgejo:
adduser --system --shell "/bin/bash" --gecos "Git Version Control" --group --disabled-password --home "/home/git" git
/home/git will be the work directory.
Create Directories #
Directory for data #
This is the directory Forgejo will store its data in, including your Git repositories.
mkdir "/var/lib/forgejo"
chown git:git "/var/lib/forgejo"
chmod 750 "/var/lib/forgejo"
Directory for config #
This is the directory Forgejo’s config, called app.ini, is stored in
mkdir "/etc/forgejo"
chown root:git "/etc/forgejo"
chmod 770 "/etc/forgejo"
Directory for logs #
mkdir /var/log/forgejo
chown git:git /var/log/forgejo/
DOnt forget to update the Log path.
MariaDB #
Install MariaDB:
apt install mariadb-server
Create database for forgejo:
SET old_passwords=0;
CREATE DATABASE forgejo CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_bin';
GRANT ALL PRIVILEGES ON forgejo.* TO 'forgejo'@'localhost' IDENTIFIED BY 'SECURE_PASSWORD' WITH GRANT OPTION;
FLUSH PRIVILEGES;
One-liner to create the DB:
mysql --execute="SET old_passwords=0; CREATE DATABASE forgejo CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_bin'; GRANT ALL PRIVILEGES ON forgejo.* TO 'forgejo'@'localhost' IDENTIFIED BY 'SECURE_PASSWORD' WITH GRANT OPTION; FLUSH PRIVILEGES;"
Binary #
Download binary from Codeberg:
wget "https://codeberg.org/forgejo/forgejo/releases/download/v12.0.4/forgejo-12.0.4-linux-amd64"
Verify GPG signature #
gpg --keyserver keys.openpgp.org --recv EB114F5E6C0DC2BCDD183550A4B61A2DC5923710
wget "https://codeberg.org/forgejo/forgejo/releases/download/v12.0.4/forgejo-12.0.4-linux-amd64.asc"
gpg --verify forgejo-*.asc
Install binary #
install forgejo-12.0.4-linux-amd64 /usr/bin/forgejo
Systemd service #
wget -O "/etc/systemd/system/forgejo.service" "https://codeberg.org/forgejo/forgejo/raw/branch/forgejo/contrib/systemd/forgejo.service"
nano "/etc/systemd/system/forgejo.service"
[Unit]
Description=Forgejo (Beyond coding. We forge.)
After=network.target
Wants=mariadb.service
After=mariadb.service
[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/forgejo/
ExecStart=/usr/bin/forgejo web --config /etc/forgejo/app.ini
Restart=always
Environment=USER=git HOME=/home/git FORGEJO_WORK_DIR=/var/lib/forgejo
[Install]
WantedBy=multi-user.target
Reload systemd:
systemctl daemon-reload
Enable and start Forgejo:
systemctl enable --now forgejo.service
Check Forgejo:
systemctl status forgejo.service
Forgejo should run on 127.0.0.1:3000.
Caddy #
Install Caddy for webserver to proxy requests to Forgejo.
git.example.com {
reverse_proxy 127.0.0.1:3000
}