(Last Updated On: December 3, 2018)

This guide will help you to Install Gitea self-hosted Git service on CentOS 7 server, and use Nginx to proxy all requests to Gitea. Gitea is a painless self-hosted Git service forked from Gogs. It is similar to GitHub, Bitbucket, and Gitlab in functionalities.

Gitea has been build to be fast, easy to use, and most painless way of setting up a self-hosted Git service with minimal resource usage. Gitea is written in Go and runs across all platforms (Linux, macOS, and Windows) and architectures that support Go.

For Ubuntu use How to Install Gitea self-hosted Git service on Ubuntu 18.04 / Ubuntu 16.04

Step 1: Update system and install git

Update all system packages and install git by running

sudo yum -y update
sudo yum -y install git wget vim
sudo reboot

Step 2: Add git system user and create directories

Add git user account that will be used by Gitea.

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

Create the required directory structure

sudo mkdir -p /etc/gitea /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 chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

Step 3: Install MariaDB database server

We will use MariaDB to store Gitea data, install MariaDB on your server by following our previous guide

Install MariaDB 10.x on Ubuntu 18.04 and CentOS 7

Create a database for Attendize

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 608168
Server version: 10.3.9-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE gitea;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "StrongPassword";
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> exit
Bye

Step 4: Install and configure Gitea

Now download gitea binary from the Downloads page. Check the latest release before downloading it.

export VER=1.6.0
wget https://github.com/go-gitea/gitea/releases/download/v${VER}/gitea-${VER}-linux-amd64

Move the downloaded binary file to the /use/local/bindirectory

chmod +x gitea-${VER}-linux-amd64
sudo mv gitea-${VER}-linux-amd64 /usr/local/bin/gitea

You can confirm version installed using

# gitea --version
Gitea version 1.6.0 built with: bindata, sqlite

Help page can be printed with --help option

# gitea --help
NAME:
   Gitea - A painless self-hosted Git service

USAGE:
   gitea [global options] command [command options] [arguments...]

VERSION:
   1.6.0 built with: bindata, sqlite

DESCRIPTION:
   By default, gitea will start serving using the webserver with no
arguments - which can alternatively be run by running the subcommand web.

COMMANDS:
     web       Start Gitea web server
     serv      This command should only be called by SSH shell
     hook      Delegate commands to corresponding Git hooks
     dump      Dump Gitea files and database
     cert      Generate self-signed certificate
     admin     Command line interface to perform common administrative operations
     generate  Command line interface for running generators
     help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version
Create a systemd service unit
sudo vim /etc/systemd/system/gitea.service

Configure the file to set UserGroup and WorkDir

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=mariadb.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

Reload systemd and restart service

sudo systemctl daemon-reload
sudo systemctl restart gitea

Also enable the service to start on boot

sudo systemctl enable gitea

Sample status output

[email protected]:~# systemctl status gitea
* gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-10-01 12:25:19 PDT; 3s ago
 Main PID: 6919 (gitea)
    Tasks: 10 (limit: 1111)
   CGroup: /system.slice/gitea.service
           `-6919 /usr/local/bin/gitea web -c /etc/gitea/app.ini

Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [T] Log path: /var/lib/gitea/log
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] Log Mode: Console(Info)
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] XORM Log Mode: Console(Info)
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] Cache Service Enabled
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] Session Service Enabled
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] SQLite3 Supported
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] Run Mode: Development
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] Gitea v1.5.1 built with: bindata, sqlite
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 [I] Listen: http://0.0.0.0:3000
Oct 01 12:25:19 centos7 gitea[6919]: 2018/10/01 12:25:19 Serving [::]:3000 with pid 6919

Step 6: Configure Nginx Reverse Proxy

If you would like to access Gitea UI using a domain name without a port, you need to configure Apache or NGINX reverse proxy

sudo yum install nginx

Create a VirtualHost reverse proxy configuration file

sudo vim /etc/nginx/conf.d/gitea.conf

Add:

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

    location / {
        proxy_pass http://localhost:3000;
    }
}

If using SSL and would like to have http to https redirect, use

server {
	listen 80;
        server_name  git.example.com;
	location / {
        	rewrite     ^ https://git.example.com$request_uri? permanent;
    }
}

server {
        listen       443 ssl;
	ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem;
        server_name git.example.com;

        location / {
            proxy_pass http://localhost:3000;
        }
}

Replace git.example.com with your actual domain name

Start the installation by visiting http://domain-name/install

Set database authentication

On the first page, set the database connection

The username and password provided should match the ones provided in the Database configuration section. If the database server is on a different host, provide the IP address under the Host section.

Set Application General Settings

Provide application URL, this can be a routable server IP address or domain name that resolves to the IP. The same should be set for SSH.

Disable User self-registration

You can disable User self-registration under “Server and Other Services Settings”. This means the admin user will manually create user accounts.

You can optionally create an admin user account. By default, root user will gain admin access automatically.

When done with the configurations, click the “Install Gitea” button to finish the installation. On a successful installation, you should be logged into Gitea administration console

Refer to Gitea Documentation for advanced configurations and usage guides. Also look at Gitea config cheatsheet.