paint-brush
Step-by-Step Guide for Installing Gitea on Debian 11 by@joshuablais
621 reads
621 reads

Step-by-Step Guide for Installing Gitea on Debian 11

by Joshua BlaisSeptember 20th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This guide explains how to install Gitea with PostgreSQL on Debian 11. It begins with system updates and PostgreSQL setup, switching to the 'SCRAM-SHA-256' scheme for better security. It covers PostgreSQL remote access configuration and creating a PostgreSQL user and database for Gitea. If permission errors occur, adjusting database ownership is recommended. The guide also includes installing and configuring Git, creating a Git user for Gitea, and installing Gitea itself. Directory structure setup and systemd service creation are explained. The guide concludes with verifying Gitea's operation on port 3000.

People Mentioned

Mention Thumbnail
featured image - Step-by-Step Guide for Installing Gitea on Debian 11
Joshua Blais HackerNoon profile picture


Here is a quick guide on how to Install Gitea with Postgresql on Debian 11


Start with a quick system update:
sudo apt-get update -y
sudo apt-get upgrade -y


Setup postgresql

sudo sh -c 'echo "deb //apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import repo signing key with:
wget --quiet -O - //www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update
sudo apt-get -y install postgresql


System setup

sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql


Next, You need to switch to ’SCRAM-SHA-256’ scheme from md5 encryption scheme for better security. If you want to connect to PostgreSQL remotely, then you need to allow your IP address in the PostgreSQL configuration file.


Open the configuration file to make changes using the following command:
sudo vim /etc/postgresql/15/main/postgresql.conf

# Inside file uncomment:

listen_addresses = 'localhost, 45.32.225.46'
password_encryption = scram-sha-256


Then, restart the systemd service:
sudo systemctl restart postgresql


Login into postgresql

sudo -u postgres psql


Inside psql:
postgres=# CREATE ROLE gitea WITH LOGIN PASSWORD 'secure@123';

postgres=# CREATE DATABASE giteadb;

postgres=# GRANT ALL PRIVILEGES ON DATABASE giteadb TO gitea;

postgres=# exit


if you receive the error:
The database settings are invalid: migrate: sync: pq: permission denied for schema public
you might have to do the following in psql after the install is complete, I did:
ALTER DATABASE gitea OWNER TO gitea


Within /etc/postgresql/15/main/pghba.conf file:

host    giteadb        gitea            134.122.38.0/32           scram-sha-256


Install and configure git:

sudo apt install git
git --version

git config --global user.name "Your Name"
git config --global user.email "[email protected]”
git config --list


Create git user for gitea

sudo adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \
   git

Install gitea:

wget //dl.gitea.com/gitea/1.20.3/gitea-1.20.3-linux-amd64 -O /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea


Make directory structure for gitea:
sudo mkdir -p /etc/gitea

sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}

sudo chown -R git:git /var/lib/gitea/

sudo chown root:git /etc/gitea

sudo chmod -R 750 /var/lib/gitea/

sudo chmod 770 /etc/gitea


Create systemd service file:
sudo vim /etc/systemd/system/gitea.service


Inside:
[Unit]
Description=Gitea
After=syslog.target
After=network.target
After=postgresql.service

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload
sudo systemctl start gitea
sudo systemctl enable gitea
sudo systemctl status gitea

# Verify running on port 3000:
netstat -tulpan | grep 3000
Navigate to port 3000 on your server and you will see it running!


Congrats, you have now dropped GitHub as your Git server.


Also published


바카라사이트 바카라사이트 온라인바카라