Install Gogs on an Ubuntu 14.04 VPS

install-gogs-on-an-ubuntu-14-04-vpsIn this guide, we will explain how to install Gogs on an Ubuntu 14.04 VPS with MariaDB and Nginx as proxy server. Gogs is an open source self-hosted Git service written in the Go programming language. This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 14.04 VPS.

Login to your VPS via SSH

ssh user@vps_IP

Update the system and install necessary packages

[user]$ sudo apt-get update && sudo apt-get -y upgrade
[user]$ sudo apt-get install software-properties-common nano git wget apt-transport-https

Install MariaDB 10.0

To add the MariaDB repository to your sources list and install the latest MariaDB server, run the following commands:

[user]$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
[user]$ sudo add-apt-repository 'deb http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main'
[user]$ sudo apt-get update
[user]$ sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

[user]$ mysql_secure_installation

Next, we need to create a database for our Gogs installation.

[user]$ mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE gogs;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY 'your_gogs_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q

Install Gogs

The following commands will download the apt registry keys for Gogs and install the Gogs binary.

[user]$ wget -qO - https://deb.packager.io/key | sudo apt-key add -
[user]$ echo "deb https://deb.packager.io/gh/pkgr/gogs trusty pkgr" | sudo tee /etc/apt/sources.list.d/gogs.list
[user]$ sudo apt-get update
[user]$ sudo apt-get install gogs

Install and configure Nginx

Ubuntu 14.04 comes with nginx version 1.4, to install the latest stable version of Nginx version 1.8, run:

[user]$ sudo add-apt-repository -y ppa:nginx/stable
[user]$ sudo apt-get update
[user]$ sudo apt-get -y install nginx

Generate a self signed ssl certificate:

[user]$ sudo mkdir -p /etc/nginx/ssl
[user]$ cd /etc/nginx/ssl
[user]$ sudo openssl genrsa -des3 -passout pass:x -out gogs.pass.key 2048
[user]$ sudo openssl rsa -passin pass:x -in gogs.pass.key -out gogs.key
[user]$ sudo rm gogs.pass.key
[user]$ sudo openssl req -new -key gogs.key -out gogs.csr
[user]$ sudo openssl x509 -req -days 365 -in gogs.csr -signkey gogs.key -out gogs.crt

If you don’t want to get warnings associated with self-signed SSL Certificates, you can purchase a trusted SSL certificate here.

Next, create a new Nginx server block:

[user]$ sudo nano /etc/nginx/sites-available/gogs.domain.tld
upstream gogs {
    server 127.0.0.1:3000;
}
server {
    listen      443 default;
    server_name gogs.domain.tld;

    ssl on;
    ssl_certificate     /etc/nginx/ssl/gogs.crt;
    ssl_certificate_key /etc/nginx/ssl/gogs.key;
    ssl_session_timeout 5m;

    ssl_ciphers               'AES128+EECDH:AES128+EDH:!aNULL';
    ssl_protocols              TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    access_log  /var/log/nginx/gogs.access.log;
    error_log   /var/log/nginx/gogs.error.log;

    location / {
        proxy_pass  http://gogs;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;

        proxy_set_header    Host            $host;
        proxy_set_header    X-Real-IP       $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto https;
    }
}

server {
    listen      80;
    server_name gogs.domain.tld;

    add_header Strict-Transport-Security max-age=2592000;
    rewrite ^ https://$server_name$request_uri? permanent;
}

Do not forget to change your_user with your username.

Activate the server block by creating a symbolic link :

[user]$ sudo ln -s /etc/nginx/sites-available/gogs.domain.tld /etc/nginx/sites-enabled/gogs.domain.tld

Test the Nginx configuration and restart nginx:

[user]$ sudo nginx -t
[user]$ sudo service nginx restart

Setup Gogs

Once the installation is complete, go to https://gogs.domain.tld/install and fill all the required options.

Database Settings
– Database Type: MySQL
– Host: 127.0.0.1:3306
– User: gogs
– Password: your_gogs_password
– Database Name: gogs

General Settings of Gogs
– Application Name: Gogs: Go Git Service
– Repository Root Path: /home/git/gogs-repositories
– Run User: gogs
– Domain: gogs.domain.tld
– SSH Port: 22
– HTTP Port: 3000
– Application URL: https://gogs.domain.tld/

Finally, click install and you’re good to go.

Administrative access is automatically granted to the first registered user.

That’s it. You have successfully installed Gogs on your Ubuntu 14.04 VPS. For more information about how to manage your Gogs installation, please refer to the official Gogs documentation.


Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately. You can also read our guide on How to Install Gogs on Ubuntu 18.04.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

2 thoughts on “Install Gogs on an Ubuntu 14.04 VPS”

  1. Hi I have installed it on 192.168.1.2 on port 3001 and I am on Raspbian Jessie which is also Debian based OS , to make site live I run sudo systemctl gogs start which starts gogs service and I can open it browser by changing the port 80 to 3001. If I launch with web server port 80 it open site enabled by a2ensite mysite.com but I want to open it using mysite.com/gogs how can I have that going ?

    Reply
    • You can use the Nginx configuration from this article and access Gogs via a domain. But first thing first, did you configure the Application URL during the Gogs installation?

      Reply

Leave a Comment