How to Install Gitea on Ubuntu 18.04

Gitea is an alternative open source, self-hosted version control system powered by git. Gitea is written in Golang and is a lightweight solution to be hosted on any platform.

Prerequisites

  • New Vultr Ubuntu 18.04 instance with at least 2 CPU cores and 1 GB RAM
  • Non-root user with sudo privileges.
  • Nginx
  • Git
  • MariaDB

Step 1: Install Nginx

Update your Vultr Ubuntu 18.04 Server instance.

sudo apt update

Install Nginx.

sudo apt -y install nginx

Once Nginx installed, test whether it is working or not by browsing the nginx test page in the browser. Open your web browser and point it to http://example.com

The following commands can be used to stop, reload, restart, check status and enable Nginx.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl restart nginx.service
sudo systemctl reload nginx.service
sudo systemctl enable nginx.service

Step 2: Install Git

Install Git.

sudo apt -y install git

Once installed, check the version:

git --version
git version 2.17.1

Step 3: Install MariaDB Database Server

Gitea supports the following databases

  • MariaDB/MySQL
  • PostgreSQL
  • SQLite
  • TiDB

For this tutorial we will install the MariaDB server and client.

sudo apt -y install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start, restart, check status and enable it.

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl restart mariadb.service
sudo systemctl status mariadb.service
sudo systemctl enable mariadb.service

After that, run the command below to secure the MariaDB server by creating a root password and disallowing remote root access.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

Restart MariaDB.

sudo systemctl restart mariadb.service

To test if MariaDB is installed, type the command below to logon to MariaDB server

sudo mysql -u root -p

Then type the password you created above to login. You will see the MariaDB welcome message.

Create a database called gitea.

CREATE DATABASE gitea;

Create a database user called giteauser with a new password.

CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the database.

GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Step 4: Prepare the Gitea Environment

Create a user to run Gitea.

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

Create the required directory structure.

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

Step 5: Install Gitea

The Gitea binary can be downloaded by the running the following commands.

sudo wget -O gitea https://dl.gitea.io/gitea/1.5.0/gitea-1.5.0-linux-amd64 
sudo chmod +x gitea

Copy the binary to a global location.

sudo cp gitea /usr/local/bin/gitea

Step 6: Create a service file to start Gitea automatically

Create a linux service file.

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

Populate the file with the following.

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

Enable and start Gitea at boot.

sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea

Run the status command.

sudo systemctl status gitea

● gitea.service - Gitea (Git with a cup of tea)
  Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: en
  Active: active (running) since Wed 2018-10-10 14:15:28 CDT; 19ms ago
 Main PID: 17769 (gitea)
   Tasks: 4 (limit: 2321)
  CGroup: /system.slice/gitea.service
       ├─17769 /usr/local/bin/gitea web -c /etc/gitea/app.ini
       └─17774 /usr/local/bin/gitea web -c /etc/gitea/app.ini

Step 7: Configure Nginx as a reverse proxy

Delete the default nginx configuration file.

sudo rm /etc/nginx/sites-enabled/default

Create a reverse proxy configuration for Gitea.

sudo nano /etc/nginx/sites-available/git

Populate the file with the following configuration.

upstream gitea {
    server 127.0.0.1:3000;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com;
    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;
    }
}

Enable the Gitea Nginx reverse proxy configuration.

sudo ln -s /etc/nginx/sites-available/git /etc/nginx/sites-enabled

Then reload the Nginx Service.

sudo systemctl reload nginx.service

Next, open your browser and browse to the server hostname or IP address.

http://example.com/install

Follow the onscreen instructions to complete the Gitea setup.

Dejar un comentario

ZPanel y Sentora en CentOS 6 x64

ZPanel y Sentora en CentOS 6 x64

ZPanel, un panel de control de alojamiento web popular, se bifurcó en 2014 a un nuevo proyecto llamado Sentora. Aprende a instalar Sentora en tu servidor con este tutorial.

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Cómo instalar Vtiger CRM Open Source Edition en CentOS 7

Aprende cómo instalar Vtiger CRM, una aplicación de gestión de relaciones con el cliente, en CentOS 7 para aumentar tus ventas y mejorar el servicio al cliente.

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Cómo instalar el servidor Counter-Strike 1.6 en Linux

Esta guía completa le mostrará cómo configurar un servidor Counter-Strike 1.6 en Linux, optimizando el rendimiento y la seguridad para el mejor juego. Aprende los pasos más recientes aquí.

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

¿Puede la IA luchar con un número cada vez mayor de ataques de ransomware?

Los ataques de ransomware van en aumento, pero ¿puede la IA ayudar a lidiar con el último virus informático? ¿Es la IA la respuesta? Lea aquí, sepa que la IA es una bendición o una perdición

ReactOS: ¿Es este el futuro de Windows?

ReactOS: ¿Es este el futuro de Windows?

ReactOS, un sistema operativo de código abierto y gratuito, está aquí con la última versión. ¿Puede satisfacer las necesidades de los usuarios de Windows de hoy en día y acabar con Microsoft? Averigüemos más sobre este estilo antiguo, pero una experiencia de sistema operativo más nueva.

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Manténgase conectado a través de la aplicación de escritorio WhatsApp 24 * 7

Whatsapp finalmente lanzó la aplicación de escritorio para usuarios de Mac y Windows. Ahora puede acceder a Whatsapp desde Windows o Mac fácilmente. Disponible para Windows 8+ y Mac OS 10.9+

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

¿Cómo puede la IA llevar la automatización de procesos al siguiente nivel?

Lea esto para saber cómo la Inteligencia Artificial se está volviendo popular entre las empresas de pequeña escala y cómo está aumentando las probabilidades de hacerlas crecer y dar ventaja a sus competidores.

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

La actualización complementaria de macOS Catalina 10.15.4 está causando más problemas que resolver

Recientemente, Apple lanzó macOS Catalina 10.15.4, una actualización complementaria para solucionar problemas, pero parece que la actualización está causando más problemas que conducen al bloqueo de las máquinas Mac. Lee este artículo para obtener más información

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

13 Herramientas comerciales de extracción de datos de Big Data

¿Qué es un sistema de archivos de diario y cómo funciona?

¿Qué es un sistema de archivos de diario y cómo funciona?

Nuestra computadora almacena todos los datos de una manera organizada conocida como sistema de archivos de diario. Es un método eficiente que permite a la computadora buscar y mostrar archivos tan pronto como presiona buscar.