How to deploy Gitea

Why Gitea and why need Gitea?

Because gitea is light weight which can run on my VPS easily.

As we all know that github can not be visited all the time in China mainland, so it is neccessary to build our own git service.

How to install?

  1. Download from official webpage and rename the binary file as gitea and make it executable. Remember that you should choose appropriate version to download.

    1
    2
    3
    4
    wget https://dl.gitea.com/gitea/1.20.4/gitea-1.20.4-linux-amd64
    mv gitea-1.20.4-linux-amd64 gitea
    chmod +x gitea
    cp gitea /usr/local/bin/gitea
  2. Download git

    1
    2
    apt update
    apt install git
  3. Creat a user naming git for gitea

    1
    2
    3
    4
    5
    6
    7
    8
    adduser \
    --system \
    --shell /bin/bash \
    --gecos 'Git Version Control' \
    --group \
    --disabled-password \
    --home /home/git \
    git
  4. Create required directory structure

    1
    2
    3
    4
    5
    6
    mkdir -p /var/lib/gitea/{custom,data,log}
    chown -R git:git /var/lib/gitea/
    chmod -R 750 /var/lib/gitea/
    mkdir /etc/gitea
    chown root:git /etc/gitea
    chmod 770 /etc/gitea
  5. Adding bash/zsh autocompletion (from 1.19)
    copy the content of bash_autocompletion into /usr/share/bash-completion/completions/gitea

  6. Preparation of database

1
2
3
4
5
6
su -c "psql" - postgres
CREATE ROLE gitea WITH LOGIN PASSWORD 'gitea';
CREATE DATABASE giteadb WITH OWNER gitea TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
exit
vim /etc/postgresql/14/main/pg_hba.conf
# add the following content
1
local    giteadb    gitea    scram-sha-256

using psql -U gitea -d giteadb to test the connection.

  1. create a new service and paste the content of template

    1
    vim /etc/systemd/system/gitea.service

    Enable and start Gitea at boot:

    1
    2
    sudo systemctl enable gitea
    sudo systemctl start gitea

    Now go to your_ip:3000 to config the installation.

How to disable register?

1
vim /etc/gitea/app.ini

Find and change as follows

1
2
DISABLE_REGISTRATION = true
ALLOW_ONLY_EXTERNAL_REGISTRATION = true

How to set the mail server?

If you are using iRedmail as me

1
2
3
4
5
6
7
[mailer]
ENABLED = true
SMTP_ADDR = your_mail_server_address
SMTP_PORT = 465
FROM = noreply<your_mail_username>
USER = your_mail_username
PASSWD = your_mail_password

Where is my Gitea?

Gitea is running on 3000 port.