5 C
Texas
angeloma
Senior Writer and partner

Install Gitea on CentOS 8



Hello, friends. In this post, we’ll show you how to install Gitea on CentOS 8

GITEA IS A COMMUNITY MANAGED LIGHTWEIGHT CODE HOSTING SOLUTION WRITTEN IN GO. IT IS PUBLISHED UNDER THE MIT LICENSE.

So we can assume that it is a lightweight alternative to Gitlab but with many features that make it ideal for many homes.

So if you have small teams or are just starting, Gitea is for you.

Install Gitea on CentOS 8

Before we start, we have to prepare the system by upgrading it and installing some pre-installation packages.

- Advertisement -

So, open a terminal or via SSH run

dnf update
dnf install git unzip gnupg2 nano wget

Although Gitea supports several database drivers, including SQLite I think MariaDB is very convenient to use.

So, install MariaDB on CentOS 8 with our post.

1) Working with MariaDB before installing Gitea

Now we can create a new database for Gite and its respective user.

So, access the MariaDB shell

mysql -u root -p

And start creating the database and the user with the corresponding permissions:

CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
GRANT ALL ON giteadb.* TO 'giteauser'@'localhost' IDENTIFIED BY 'giteapss';
FLUSH PRIVILEGES;
exit;

After that, you have to add some parameters to the MariaDB configuration.

So, open the file:

nano /etc/my.cnf.d/server.cnf

And add the following just below the [mysqld] section

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

Save your changes and close the editor. And restart the MariaDB service to apply the changes.

systemctl restart mariadb

2) Install Gitea on CentOS

Now we can download the Gitea binary which is the easiest way to do this process.

So, as of this writing, the latest stable version of Gitea is 1.13.1 so you have to update the commands with the number of the latest stable version.

So, download it using wget

wget https://dl.gitea.io/gitea/1.13.1/gitea-1.13.1-linux-amd64

Move it to the system binaries folder:

mv gitea-1.13.1-linux-amd64 /usr/bin/gitea

And assign it to run permissions:

chmod 755 /usr/bin/gitea

It is a good idea to handle Gitea as a system service so we have to create a new entry for it

nano /etc/systemd/system/gitea.service

And add the following content

[Unit]
 Description=Gitea
 After=syslog.target
 After=network.target
 After=mysql.service

 [Service]
 RestartSec=2s
 Type=simple
 User=git
 Group=git
 WorkingDirectory=/var/lib/gitea/
 ExecStart=/usr/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

Save the changes and close the editor.

To apply the changes refresh the system services cache:

systemctl daemon-reload

Now, enable and start Gitea-

systemctl enable gitea
systemctl start gitea

And check the status of it

systemctl status gitea
● gitea.service - Gitea
    Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: disabled)
    Active: active (running) since Sat 2021-02-20 16:27:12 CET; 8s ago
  Main PID: 54969 (gitea)
     Tasks: 8 (limit: 24338)
    Memory: 153.6M
    CGroup: /system.slice/gitea.service
            └─54969 /usr/bin/gitea web -c /etc/gitea/app.ini
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 …s/storage/storage.go:145:initAvatars() [I] Initialising Avatar storage with type: 
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 …les/storage/local.go:43:NewLocalStorage() [I] Creating new Local Storage at /var/lib/gitea/data/avatars
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 …s/storage/storage.go:163:initRepoAvatars() [I] Initialising Repository Avatar storage with type: 
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 …les/storage/local.go:43:NewLocalStorage() [I] Creating new Local Storage at /var/lib/gitea/data/repo-avatars
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 …s/storage/storage.go:157:initLFS() [I] Initialising LFS storage with type: 
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 …les/storage/local.go:43:NewLocalStorage() [I] Creating new Local Storage at /var/lib/gitea/data/lfs
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 routers/init.go:174:GlobalInit() [I] SQLite3 Supported
 Feb 20 16:27:12 osradar gitea[54969]: 2021/02/20 16:27:12 routers/init.go:56:checkRunMode() [I] Run Mode: Production
 Feb 20 16:27:13 osradar gitea[54969]: 2021/02/20 16:27:13 cmd/web.go:163:runWeb() [I] Listen: http://0.0.0.0:3000
 Feb 20 16:27:13 osradar gitea[54969]: 2021/02/20 16:27:13 …s/graceful/server.go:55:NewServer() [I] Starting new server: tcp:0.0.0.0:3000 on PID: 54969

By default, Gite uses port 3000 so we have to open it in the Firewall.

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

This will set it up, but it’s a good idea to do some more configuration.

Optional: Configuring Ngnix as the reverse proxy

To facilitate access you need to configure Nginx as a Reverse Proxy.

First, install it:

dnf install nginx

And now create the configuration file for Gitea:

nano /etc/nginx/conf.d/gitea.conf

And add the following content:

upstream gitea {
      server 127.0.0.1:3000;
  }
  server {
      listen 80;
      server_name angtest.ga;
      root /var/lib/gitea/public;
      access_log off;
      error_log off;
 location / { 
 try_files maintain.html $uri $uri/index.html @node;
 } 
 location @node {   
 client_max_body_size 0;
 proxy_pass http://localhost:3000;
 proxy_set_header X-Forwarded-For
 $proxy_add_x_forwarded_for;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header Host $http_host;
 proxy_set_header X-Forwarded-Proto $scheme; 
 proxy_max_temp_file_size 0;
 proxy_redirect off;
 proxy_read_timeout 120;
 }
  }
1.- Installing Gitea on CentOS 8
1.- Installing Gitea on CentOS 8

From this content, you have to replace the server_name value with yours.

Save the changes and close the file.

To apply the changes, restart the Nginx service.

Optional: Enable HTTPS for Gitea

We can install certificates thanks to Let’s Encrypt using Certbot. This process is recommended to secure web access.

Certbot is not in the CentOS 8 repositories but we can install it thanks to Snap.

So, enable the EPEL repository:

dnf install epel-release

Install the snapd package:

dnf install snapd

Enable it by running the following command:

systemctl enable --now snapd.socket

And enable the installation of classics packages.

ln -s /var/lib/snapd/snapd/snap /snap

After that install the core package which is the initial Snapd package.

snap install core

Now install Certbot by running:

snap install --classic certbot

And create a symbolic link to use the snap command from anywhere in promt without any problems:

ln -s /snap/bin/certbot /usr/bin/certbot

Finally, download and install the certificates by running

certbot --redirect --hsts --staple-ocsp --agree-tos --email [email protected] --nginx -d angtest.ga

In this command you have to replace the values of --email and -d with your own.

Testing Gitea installation

You can now open your web browser and go to https://your-domain/install to complete the installation.

First, enter the database credentials we defined earlier.

2.- Configuring Gitea before using it
2.- Configuring Gitea before using it

On the bottom section, we have some other settings that we can change. The most important thing here is the BaseURL which you have to replace with your domain and the creation of the admin user and password.

3.- Installing Gitea
3.- Installing Gitea

When finished, you can complete the installation and the installer will redirect you to the dashboard. From there you can start working.

4.- Gitea Dashboard
4.- Gitea Dashboard

Conclusion

Gitea aims to be a solid alternative to Gitlab for hosting code in private workgroups. Gitea is lighter but has the capabilities to become a powerful and compliant software.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article