This guide will help you to Install Gitea self-hosted Git service on CentOS 7 / CentOS 8 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
Step 1: Update system and install git
Put SELinux in Permissive mode:
sudo setenforce 0
sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
Update all system packages and install git by running
sudo yum -y update
sudo yum -y install git wget vim bash-completion
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 Gitea:
# 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.
curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest |grep browser_download_url | cut -d '"' -f 4 | grep '\linux-amd64$' | wget -i -
Move the downloaded binary file to the /use/local/bin
directory
chmod +x gitea-*-linux-amd64
sudo mv gitea-*-linux-amd64 /usr/local/bin/gitea
You can confirm version installed using
$ gitea --version
Gitea version 1.14.4 built with GNU Make 4.1, go1.16.5 : bindata, sqlite, sqlite_unlock_notify
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.14.4 built with GNU Make 4.1, go1.16.5 : bindata, sqlite, sqlite_unlock_notify
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
migrate Migrate the database
keys This command queries the Gitea database to get the authorized command for a given ssh key fingerprint
convert Convert the database
doctor Diagnose problems
manager Manage the running gitea process
embedded Extract embedded resources
migrate-storage Migrate the storage
docs Output CLI documentation
dump-repo Dump the repository from git/github/gitea/gitlab
restore-repo Restore the repository from disk
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--port value, -p value Temporary port number to prevent conflict (default: "3000")
--install-port value Temporary port number to run the install page on to prevent conflict (default: "3000")
--pid value, -P value Custom pid file path (default: "/run/gitea.pid")
--custom-path value, -C value Custom path file path (default: "/usr/local/bin/custom")
--config value, -c value Custom configuration file path (default: "/usr/local/bin/custom/conf/app.ini")
--version, -v print the version
--work-path value, -w value Set the gitea working path (default: "/usr/local/bin")
--help, -h show help
DEFAULT CONFIGURATION:
CustomPath: /usr/local/bin/custom
CustomConf: /usr/local/bin/custom/conf/app.ini
AppPath: /usr/local/bin/gitea
AppWorkPath: /usr/local/bin
Create a systemd service unit
sudo vim /etc/systemd/system/gitea.service
Configure the file to set User, Group 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
Confirm service status is running:
systemctl status gitea
● gitea.service - Gitea (Git with a cup of tea)
Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-07-13 23:54:47 UTC; 8s ago
Main PID: 27506 (gitea)
Tasks: 8 (limit: 23694)
Memory: 128.6M
CGroup: /system.slice/gitea.service
└─27506 /usr/local/bin/gitea web -c /etc/gitea/app.ini
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 ...dules/setting/git.go:101:newGit() [I] Git Version: 2.27.0, Wire Protocol Version 2>
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 routers/init.go:93:PreInstallInit() [T] AppPath: /usr/local/bin/gitea
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 routers/init.go:94:PreInstallInit() [T] AppWorkPath: /var/lib/gitea
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 routers/init.go:95:PreInstallInit() [T] Custom path: /var/lib/gitea/custom
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 routers/init.go:96:PreInstallInit() [T] Log path: /var/lib/gitea/log
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 routers/init.go:97:PreInstallInit() [T] Preparing to run install page
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 routers/init.go:100:PreInstallInit() [I] SQLite3 Supported
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 cmd/web.go:189:listen() [I] Listen: http://0.0.0.0:3000
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 ...s/graceful/server.go:62:NewServer() [I] Starting new Web server: tcp:0.0.0.0:3000 >
Jul 13 23:54:47 rocky-01.novalocal gitea[27506]: 2021/07/13 23:54:47 ...s/graceful/server.go:75:func1() [D] Starting server on tcp:0.0.0.0:3000 (PID: 2750
Step 5: 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.
Restart Nginx service:
sudo systemctl restart nginx
Step 6: Finish Gitea installation on CentOS 8 / CentOS 7
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.