Skip to content
Menu
vernon.wenberg.net
vernon.wenberg.net
January 3, 2021February 21, 2022

Install Gogs on Ubuntu 20.04 with MariaDB

These instructions will install Gogs on an Ubuntu 20.04 server using the MariaDB back-end. Gogs is a
self-hosted front-end to Git. Gogs is extremely lightweight and comes in a single binary file. It also
supports multiple back-end databases including PostgreSQL, MySQL, or SQLite3.

These commands assume you are running as root or sudo. All scripts also rely on the install directory
being /home/git. Remember to set your own password wherever a password is needed.

Install MariaDB

apt install mariadb-server
mysql_secure_installation

Download and extract the latest/desired version of Gogs from dl.gogs.io/.

wget https://dl.gogs.io/0.12.3/gogs_0.12.3_linux_amd64.tar.gz
tar xzvf gogs_0.12.3_linux_amd64.tar.gz

Create a systemd service file in /lib/systemd/system/gogs.service.

[Unit]
Description=Gogs
After=syslog.target
After=network.target

[Service]
LimitMEMLOCK=infinity
LimitNOFILE=4000
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/home/git
ExecStart=/home/git/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git GOGS_WORK_DIR=/home/git

[Install]
WantedBy=multi-user.target

Enable the Gogs service.

systemctl enable gogs

Start the Gogs service

systemctl start gogs

Install nginx.

apt install nginx

Log in to MariaDB to create a user and database.

mysql -u root -p

Create the database.

CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE
utf8mb4_general_ci;

Create database user and grant privileges.

CREATE USER 'gogs'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Create nginx proxy file. Note that I am using an SSL certificate here. If you do not have
your own certificate, you can use certbot.

server {
    listen 80;
    server_name gogs.domain.edu;
    return 301 https://$server_name$request_uri;
}
server {
    listen 443 ssl;
    server_name gogs.domain.edu;
    ssl_certificate /etc/nginx/ssl/cert.pem;
    ssl_certificate_key /etc/nginx/ssl/key.key;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:3000/;
    }
}

Test your nginx configuration.

nginx -t

Restart nginx.

systemctl restart nginx

Set the external URL by editing /home/git/custom/conf/app.ini.

Continue the installation using the web interface https://gogs.domain.edu.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to print (Opens in new window) Print
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn

Like this:

Like Loading...

Related

Disclaimer

These posts are notes for me. These are not guides and you should not use these instructions as step-by-step instructions without knowing what they do.

Recent Posts

  • HPE Aruba-CX Notes
  • Docker Reference
  • Useful Commands for Windows Subsystem for Linux
  • FortiManager Local-In Policy
  • Mount Google Drive in Linux using rclone

Mastodon

  1. Loading Mastodon feed...

©2025 vernon.wenberg.net | Powered by WordPress and Superb Themes!
%d