Install Gitea

Download the binary

$ VERSION_GITEA=1.22.0
$ wget https://dl.gitea.com/gitea/$VERSION_GITEA/gitea-$VERSION_GITEA-linux-amd64
$ chmod +x gitea-$VERSION_GITEA-linux-amd64

Create git user

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

Create directories

$ sudo mkdir -p /var/lib/gitea/{custom,data,log}
$ sudo chown -R git:git /var/lib/gitea/
$ sudo chmod -R 750 /var/lib/gitea/
$ sudo mkdir /etc/gitea
$ sudo chown root:git /etc/gitea
$ sudo chmod 770 /etc/gitea
$ sudo cp gitea-$VERSION_GITEA-linux-amd64 /usr/local/bin/gitea

It's a little dirty to give all the permission to the gitea repository, but, it's just for the installation, after that, you change the permission to the /etc/gitea/ repository.

Create the service

$ sudo cat /etc/systemd/system/gitea.service
[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target
Wants=mysql.service
After=mysql.service

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

[Install]
WantedBy=multi-user.target

And enable the service

$ sudo systemctl enable gitea.service

Configure NGinx as proxy

$ sudo apt install nginx

And add the below code in the http section:

http {
  /* ... */
  server {
        listen 80;
        server_name gitlab.bucchino.org;

        location / {
            client_max_body_size 512M;
            proxy_pass http://localhost:3000;
            proxy_set_header Connection $http_connection;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }

}

Configure MySQL

mysql> create user '<gitea account>'@'localhost' identified by '<gitea password>';
mysql> create database gitea;
mysql> grant all privileges on gitea.* to '<gitea account>'@'localhost';

To finish

$ sudo chmod -R 750 /etc/gitea
$ sudo chmod -R 640 /etc/gitea/app.ini