How to install Gitea on CentOS 8

Gitea is an open source git server written in Go. It includes a repository file editor, project issue tracking, user management, notifications, an embedded wiki, and more.

Gitea is a lightweight application that can be installed on less powerful systems. If you’re looking for a much lower memory alternative to Gitlab and don’t need all the bells and whistles that Gitlab has to offer, give Gitea a try.

This article shows you how to install and configure Gitea on CentOS 8.

Prerequisites

Gitea supports SQLite, PostgreSQL and MySQL / MariaDB as a database.

We will be using SQLite. It is a lightweight database that stores data in a single file. If SQLite is not installed on your CentOS machine, you can install it by running the following command as the sudo user:

sudo dnf install sqlite

We assume that SELinux is either disabled or set to permissive mode.

Installing Gitea

Gitea can be installed from source, binary, and as a package. It can also be deployed as a Docker image. We will install Gitea using a binary.

Install Git

The first step is to install Git on CentOS:

sudo dnf install git

Verify the installation by displaying the Git version:

git --version

git version 2.18.4

Create Git User

Create a new system user to run the Gitea app:

sudo useradd    --system    --shell /bin/bash    --comment 'Git Version Control'    --create-home    --home /home/git    git

The command will create a new user and group named git and set the home directory to / home / git.

Download Gitea binary

The latest Gitea binary can be downloaded from the Gitea download page. Make sure you download the correct binary for your architecture.

At the time of this writing, the latest version is 1.12.3. If a newer version is available, change the VERSION variable in the command below.

Use wget to download the Gitea binary in the / tmp directory:

VERSION=1.12.3sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64

You can run the binary from anywhere. We’ll follow the convention and move the binary to the / usr / local / bin directory:

sudo mv /tmp/gitea /usr/local/bin

Make a binary executable:

sudo chmod +x /usr/local/bin/gitea

The following commands will create the required directories and set the required permissions and owner:

sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
sudo chown git: /var/lib/gitea/{data,indexers,log}
sudo chmod 750 /var/lib/gitea/{data,indexers,log}
sudo mkdir /etc/giteasudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

The directory structure above is recommended by the official Gitea documentation.

The permissions for the / etc / gitea directory are set 770 so that the installation wizard can create configuration files. Once the installation is complete, we will set stricter permissions.

Create system module file

Gitea provides a Systemd module file configured according to our settings.

Upload the file to the / etc / systemd / system / directory by typing:

sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service -P /etc/systemd/system/

After that enable and start the Gitea service:

sudo systemctl daemon-reload
sudo systemctl enable --now gitea

Make sure the service started successfully:

sudo systemctl status gitea

● gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-01-04 21:27:23 UTC; 3s ago
 Main PID: 14804 (gitea)
    Tasks: 9 (limit: 1152)
   CGroup: /system.slice/gitea.service
           └─14804 /usr/local/bin/gitea web --config /etc/gitea/app.ini
...

Configure Gitea

Now that Gitea is running, it’s time to complete the installation via the web interface.

By default, Gitea listens for connections on port 3000 on all network interfaces. You need to configure your firewall to allow access to the Gitea web interface:

sudo firewall-cmd --permanent --zone=public --add-port=3000/tcp
sudo firewall-cmd --reload

Open your browser, enter http: // YOUR_DOMAIN_IR_IP: 3000 / install and the initial configuration page appears:

Fill in the required fields as follows:

Database settings:

  • Database type: SQLite3
  • Path: use an absolute path, /var/lib/gitea/data/gitea.db

General application settings:

  • Site Name – Enter the name of your organization.
  • Repository root path – Leave the default / home / git / gitea-repositories.
  • Git LFS Root Path – Leave the default / var / lib / gitea / data / lfs.
  • Run as user – git
  • SSH Server Domain – Enter the IP address of your domain or server.
  • SSH port is 22, change it if SSH is listening on a different port
  • Gitea HTTP Listening Port – 3000
  • Gitea Base URL – Use http and the IP address of your domain or server.
  • Log path – leave the default / var / lib / gitea / log

You can later change the settings by editing the Gitea config file.

Once done, click the “Install Gitea” button. Installation takes place instantly. Once completed, you will be redirected to the login page.

Click on the Register Now link. The first registered user is automatically added to the Administrators group.

To make the installation more secure, change the permissions on the read-only Gitea configuration file using:

sudo chmod 750 /etc/gitea
sudo chmod 640 /etc/gitea/app.ini

That’s all. Gitea was installed on your CentOS machine.

Configuring Nginx as SSL Termination Proxy

This step is optional, but highly recommended. To use Nginx as a reverse proxy, you need to have a domain or subdomain pointing to your server’s public IP address. In this tutorial, we will be using git.example.com.

First, install Nginx and create a free Let’s Encrypt SSL certificate using the instructions below:

  • How to install Nginx on CentOS
  • Secure Nginx with Let’s Encrypt

After that, open a text editor and edit the domain server block file:

sudo nano /etc/nginx/conf.d/git.example.com.conf

/etc/nginx/conf.d/git.example.com.conf

server {
    listen 80;
    server_name git.example.com;

    include snippets/letsencrypt.conf;
    return 301 https://git.example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name git.example.com;

    proxy_read_timeout 720s;
    proxy_connect_timeout 720s;
    proxy_send_timeout 720s;

    client_max_body_size 50m;

    # Proxy headers
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/git.example.com/chain.pem;
    include snippets/letsencrypt.conf;
    include snippets/ssl.conf;

    # log files
    access_log /var/log/nginx/git.example.com.access.log;
    error_log /var/log/nginx/git.example.com.error.log;

    # Handle / requests
    location / {
       proxy_redirect off;
       proxy_pass http://127.0.0.1:3000;
    }
}

Remember to replace git.example.com with your Gitea domain and provide the correct path to your SSL certificate files. HTTP – traffic is redirected to HTTPS.

After that, restart the Nginx service for the changes to take effect:

sudo systemctl restart nginx

Then change the Gitea domain and root URL. To do this, open the configuration file and edit the following lines:

sudo nano /etc/gitea/app.ini

/etc/gitea/app.ini

[server]
DOMAIN           = git.example.com
ROOT_URL         = https://git.example.com/

Restart the Gitea service by entering:

sudo systemctl restart gitea

At this point, the Gitea proxy is configured and you can access it at: https://git.example.com

Configuring Email Notifications

You can install Postfix or use a transactional mail service to send email notifications.

To enable email notifications, open the configuration file and edit the following lines:

sudo nano /etc/gitea/app.ini

/etc/gitea/app.ini

[mailer]
ENABLED = true
HOST    = SMTP_SERVER:SMTP_PORT
FROM    = SENDER_EMAIL
USER    = SMTP_USER
PASSWD  = YOUR_SMTP_PASSWORD

Make sure you are using the correct SMTP server information.

Every time you edit the app.ini file, you need to restart the Gitea service for the changes to take effect:

sudo systemctl restart gitea

To check your settings and send a test email, login to Gitea and navigate to: Site Administration> Configuration> SMTP Mailer Configuration.

Gitea also lets you connect to Slack by creating a webhook and sending notifications to your Slack channels.

Gitea update

Upgrading to the latest version of Gitea is a simple task. You only need to download and replace the binary.

  1. Stop the Gitea service:
    sudo systemctl stop gitea
  2. Download the latest Gitea binary and move it to the / usr / local / bin directory:
    VERSION=<THE_LATEST_GITEA_VERSION>wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64sudo mv /tmp/gitea /usr/local/bin
  3. Make a binary executable:
    sudo chmod +x /usr/local/bin/gitea
  4. Restart the Gitea service:
    sudo systemctl restart gitea

That’s all.

Output

We showed you how to install Gitea on CentOS 8. You should now visit the Gitea documentation page and learn how to customize your installation and create your first project.

If you have any questions, do not hesitate to leave comments below.

Sidebar