We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install Gitea Git service on CentOS 7/8 with Nginx

Learn how to – Install Gitea Git service on CentOS 7/8 with Nginx.

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 running the following script:

curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s --
sudo yum -y install epel-release
sudo yum -y install MariaDB-server MariaDB-client MariaDB-backup

Start and enable the service.

sudo systemctl enable --now mariadb

Create a database for Gitea:

$ sudo mysql -u root
CREATE DATABASE gitea;
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "StrongPassword";
FLUSH PRIVILEGES;
exit

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/bindirectory

chmod +x gitea-*-linux-amd64
sudo mv gitea-*-linux-amd64 /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea

You can confirm version installed using

$ gitea --version
Gitea version 1.19.3 built with GNU Make 4.1, go1.20.4 : 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.19.3 built with GNU Make 4.1, go1.20.4 : 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 and optionally fix 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")
   --quiet, -q                    Only display Fatal logging errors until logging is set-up
   --verbose                      Set initial logging to TRACE level until logging is properly set-up
   --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 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

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 Mon 2023-05-08 09:01:07 UTC; 12s ago
 Main PID: 2229 (gitea)
   CGroup: /system.slice/gitea.service
           └─2229 /usr/local/bin/gitea web -c /etc/gitea/app.ini

May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/local/bin/gitea
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/custom
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/install/setting.go:25:PreloadSettings() [I] Configuration file: /etc/gitea/app.ini
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/install/setting.go:26:PreloadSettings() [I] Prepare to run install page
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/install/setting.go:29:PreloadSettings() [I] SQLite3 is supported
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 cmd/web.go:220:listen() [I] [6458ba54-3] Listen: http://0.0.0.0:3000
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 cmd/web.go:224:listen() [I] [6458ba54-3] AppURL(ROOT_URL): http://localhost:3000/
May 08 09:01:08 cent7.mylab.io gitea[2229]: 2023/05/08 09:01:08 ...s/graceful/server.go:62:NewServer() [I] [6458ba54-3] Starting new Web server: tcp:0.0.0.0:3000 on PID: 2229

The service is running on port 3000.

$ sudo ss -tunelp | grep -i gitea
tcp    LISTEN     0      128    [::]:3000               [::]:*                   users:(("gitea",pid=2229,fd=6)) uid:997 ino:21121 sk:ffff9806ad31a940 v6only:0 <->

If you don’t need proxy you can access Git service on http://Server_IP:3000

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 from Web UI

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.

More guides:

How To Install and Configure GitLab on CentOS 8 / RHEL 8

Gitleaks – How to Audit git repository for secrets

How to Disable User Creation (Signup) on GitLab welcome page

How To Secure GitLab Server with SSL Certificate

2
36.785,70