1.6 C
Amsterdam

Install Gitea on Ubuntu 20.04

angeloma
angeloma
Senior Writer and partner

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

Gitea 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 Ubuntu 20.04

Preparing the system

Before we start with the installation, we need to make a few adjustments so that we can get it right.

First, open a terminal or an SSH session and update Ubuntu

sudo apt update
sudo apt upgrade

Next, install some packages needed for the installation:

sudo apt install git unzip gnupg2

After that, install and configure MariaDB. With this post, you will have no problems with that:

How to install MariaDB 10.5 on Ubuntu 20.04 / Ubuntu 18.04?

Then we can continue

Configuring MariaDB for Gitea

Now we need to configure MariaDB to work with Gitea.

First, create a new database, user for Gitea.

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

You can replace the database name, username, and password with whatever you want.

Next, you need to add some parameters to the MariaDB configuration file.

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

In short, you have to add the following values inside the [mysqld] section

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

Save the changes and exit the editor.

Now to apply these changes to the program, you have to restart the MariaDB service.

sudo systemctl restart mariadb

Install Gitea on Ubuntu 20.04

Before installing Gitea, you should create a new system user so that you can use Git without any problems.

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

Next, create the directory structure necessary for Gitea to work.

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

Now assign the appropriate owner and permissions.

sudo chown -R git:git /var/lib/gitea/{custom,data,log}
sudo chmod -R 750 /var/lib/gitea/{custom,data,log}

Do the same with any other configuration directory that is required:

sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

After this, you can download the Gitea binary.

wget https://dl.gitea.io/gitea/1.13.1/gitea-1.13.1-linux-amd64
--2021-01-26 18:17:28--  https://dl.gitea.io/gitea/1.13.1/gitea-1.13.1-linux-amd64
 Resolving dl.gitea.io (dl.gitea.io)… 2604:1380:2000:c600::5, 147.75.84.81
 Connecting to dl.gitea.io (dl.gitea.io)|2604:1380:2000:c600::5|:443… connected.
 HTTP request sent, awaiting response… 200 OK
 Length: 115836856 (110M) [application/octet-stream]
 Saving to: ‘gitea-1.13.1-linux-amd64’
 gitea-1.13.1-linux-amd64                   100%[=====================================================================================>] 110.47M  66.5MB/s    in 1.7s    
 2021-01-26 18:17:30 (66.5 MB/s) - ‘gitea-1.13.1-linux-amd64’ saved [115836856/115836856]

After downloading it, copy it to the system binaries folder and assign it execution permissions

sudo cp gitea-1.13.1-linux-amd64 /usr/bin/gitea
sudo chmod 755 /usr/bin/gitea

It is recommended to manage Gitea as a system service, so let’s create a new systemd entry for Gitea.

sudo nano /etc/systemd/system/gitea.service

And add the following:

[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.

Then, refresh all system daemons.

sudo systemctl daemon-reload

Now, make Gitea start with the system and run it:

sudo systemctl enable gitea
sudo systemctl start gitea

You can check the status of the Gitea service with the command:

sudo systemctl status gitea

Gitea is available at http://localhost:3000 but it is convenient to use a reverse proxy like Nginx.

Configuring Nginx as the reverse proxy for Gitea

The best thing to do is to make Nginx the reverse proxy for Gitea. This will make access easier.

So, install it:

sudo apt install nginx

And then, create a new configuration file for Gitea.

sudo 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 osradartest.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.- Configuring Nginx
1.- Configuring Nginx

Save the changes and close the editor. To apply the changes, just restart the service.

sudo systemctl restart nginx

Optionally, but recommended, you can enable HTTPS using Let’s Encrypt.

So, install it together with the Nginx plugin.

sudo apt install certbot python3-certbot-nginx

And get the certificate, by running:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d your-domain

Then restart Nginx.

Remember that certificates expire after 90 days, so you will have to renew them.

Access to Gitea

Now open a web browser and go to http://your-domain or https://your-domain.

You will see the Gitea installation screen.

2.- Install Gitea on Ubuntu 20.04
2.- Install Gitea on Ubuntu 20.04

At first, you will have to configure the parameters of the database we have created.

Further down you will have more options, the most relevant are the Base Url that you will have to modify for your domain. And the creation of the administrator account.

3.- Configuring Gitea before the first use
3.- Configuring Gitea before the first use

If all goes well, when you click on Install Gitea, you will be redirected to the dashboard where you can start administering Gitea.

4.- Gitea on Ubuntu 20.04
4.- Gitea on Ubuntu 20.04

So, enjoy it

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 -

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Donate to Osradar

Latest article

x