Install your own Git server with web interface with Gogs

in utopian-io •  7 years ago  (edited)

Install your own Git server with web interface with Gogs

git_gogs.png

What Will I Learn?

  • You will learn to install Git server
  • You will learn to install Gogs web interface for Git
  • You will learn to configure Git and Gogs

Requirements

  • Dedicated Server or VPS or VM
  • Linux server with Debian or Ubuntu OS installed
  • Basic command line knowledge

Difficulty

  • Intermediate

Tutorial Contents

In this tutorial, we will install a Git server as well as the Gogs web interface from source code.
We will also configure Git and Gogs.
In the tutorial, the installation will be done in a VM (Virtual Machine) dedicated to this tuto. I will do the installation on Debian Stretch.
For this tuto, we will install Gogs via the source files. For DBMS (database manager) I would use MariaDB.
Gogs is coded in Go, so we will install it to make Gogs work.

The demo of Gogs interface : https://try.gogs.io/explore/repos

Installation of prerequisite

In shell, install Git and MariaDB packages with apt.

sudo apt install git mysql-server

Once Mysql-Server and Git installed, we will create a user account for Git :

sudo adduser --disabled-login --gecos 'Gogs' git

Let's connect as Git

sudo su - git

Go to the Git home folder, create local folder and put us in local :

> cd /home/git && mkdir local && cd local

Then let's download Go from the official Golang website ( https://golang.org/dl ), the last version is Go 1.10 :

wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz

Extract the Go archive :

tar xvf go1.10.linux-amd64.tar.gz

Go is now installed in the local folder.
Let's save the environment variables with these commands :

echo 'export GOROOT=$HOME/local/go' >> $HOME/.bashrc
echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc
source $HOME/.bashrc

Download and install the dependencies :

go get -u github.com/gogits/gogs

Gogs is now downloaded. To install it, let's go to the right folder and run it:

cd $GOPATH/src/github.com/gogits/gogs
go build

Your Git server with web interface should be up and running, to start the web interface enter :

cd $GOPATH/src/github.com/gogits/gogs
./gogs web

If all goes well, your server should be accessible via its local ip on port 3000. In the case of an installation on your own machine, it should be accessible at http://127.0.0.1:3000.

Disconnect from Git account :

exit

Before finishing the installation, we will create the database.
Let's connect as root and connect us to Mysql with root user :

su
mysql -u root

In the Mysql console, let's create the Gogs database :

CREATE DATABASE gogs CHARACTER SET 'utf8';

Mysql should answer you "Query OK".

Always in the Mysql console, let's create a Gogs user :

CREATE USER 'gogs'@'localhost' IDENTIFIED BY 'password';

Let's give all privileges to the Gogs user for the Gogs database :

use gogs;
GRANT ALL PRIVILEGES ON * gogs* TO 'gogs'@'localhost';
FLUSH PRIVILEGES;

Database is ready ! Let's disconnect from Mysql :

exit;

Let's reconnect as Git and restart the Gogs web server in the background :

sudo su - git
cd $GOPATH/src/github.com/gogits/gogs
./gogs web &

Now connect to the server ip with port 3000 via your browser. Replace '127.0.0.1' by server ip. Example URL to acces web server of Gogs is : http://127.0.0.1:3000 .

The installation interface looks like this :

Gogs_Web-install.png

Enter the name and password of the Gogs database.
Complete general settings of Gogs section. For the system user specify Git user.
In domain, enter you domain name or the ip of server.

In optional parameters you can set it up as you like.

After complete the installation form, if you have error "Error 1709: Index column size too large. The maximum column size is 767 bytes." you need upgrade your Mysql package.
To update Mysql, add its repository :

sudo apt-get install software-properties-common dirmngr
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mariadb.mirrors.ovh.net/MariaDB/repo/10.2/debian stretch main'

Refresh you repository et upgrade Mysql :

sudo apt-get update
sudo apt-get install mariadb-server

Return to install web page and finish installation.

You can access the Gogs server with its ipand port 3000, by example for me : http://192.168.1.103:3000 .

Enjoy now your git server with its web interface !

screen1.png

screen2.png

This is the end of this tutorial hoping to help you, bye :)

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

The contribution cannot be approved because it doesn't follow the rule:

  • Tutorials must be technical instructions that teach non-trivial aspects of an Open Source project.
  • Your tutorial mainly covers:
    • Installation of dependencies
    • Installation and configuration of Go Environment
    • Downloading and installation of Gogs
    • Creation and preparation of the database
  • Contributions in the tutorials category are expected to teach technical concepts of the project with the linked repository. But only one part of the tutorial is directly about Gogs and it's not non-trivial(simple installation process), the tutorial cannot be approved.

You can contact us on Discord.
[utopian-moderator]

Hey @roj, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!