Install Gogs on Ubuntu 18 server with MariaDB and Nginx


Install requirements:

apt install nginx mariadb-server mariadb-client git certbot python-certbot-nginx

Configure MariaDB:


Add user for gogs:

adduser --disabled-login git

Change user to git:

su - git

Download binary from [Gogs site][1] according to your architecture:

wget [URL]

Extarct the tar file:

tar -xf gogs*

Go back to root:


Copy the Gogs’s systemd unit file to an apropriate folder, eg.: /etc/systemd/system/:

cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/

Refresh the unit files:

systemctl daemon-reload

Enable Gogs:

systemctl enable gogs

Gogs binary comes with an sql dump to create and config the database for Gogs:

mysql -u root -p < /home/git/gogs/scripts/mysql.sql

Login to MariaDB:

mysql -u root -p

Check databases, gogs should be there:

MariaDB [(none)]> show databases;
| Database           |
| gogs               | <-------
| information_schema |
| mysql              |
| performance_schema |

Create user:

create user '[USER]'@'localhots' identified by '[PASSWORD]';

Grant privileges for the new user:

grant all on gogs.* to '[USER]'@'localhost' identified by '[PASS]' with grant option;
flush privileges;


Get an SSL certificate from Let’s Encrypt:

certbot certonly -d

An example code to configure Nginx:

nano /etc/nginx/nginx.conf
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;


	location / {

server {

	listen 80;
	listen [::]:80;

	return 301 https://$server_name$request_uri;


Start Gogs service:

systemctl start gogs