Gogs(Go Git Service) a painless self-hosted Git Service written in Go. As its built with Go, so we automatically get its cross-platform compatibility that it supports, including Linux, Mac OS and Windows. Gogs has really low footprints so its easy on low system resources. In this article we will guide you with simple steps and to get it up and running on Ubuntu 15.04 with its web interface, admin dashboard and all its operational functions where you can preferably host your codes because of its many great features, easy to use and access.
Basic Requirements
In order to setup Gogs we need an update OS with its basic resources and following mandatory packages.
- MySQL version 5.1 or greater.
- git(bash) version 1.8.0 or greater
We will setup gogs installation and its configurations within the following environment as a general user with sudo privileges.
Gogs (Go Git Service) | |
Base Operating System | Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic x86_64) |
Database | mysql Ver 14.14 Distrib 5.6.24, for debian-linux-gnu (x86_64) |
Go | go1.4.2.linux-amd64.tar.gz |
Git | git version 2.1.4 |
RAM and CPU | 2 GB , 1.0 GHZ |
Hard Disk | 30 GB |
System Update
Before starting with installation we need to make sure that our system is upto date, we can always do so by using following command.
root@ubuntu-15:~#apt-get update
Create New User
We are going to create a new user that we will use for the whole setup and installation under this user.
root@ubuntu-15:~# adduser git
Grant super user privileges to user "git"
root@ubuntu-15:~# visudo
# User privilege specification
root ALL=(ALL:ALL) ALL
git ALL=(ALL:ALL) ALL
Start Installation Process
First we need to install the prerequisites that are necessary for Gogs setup.
Git Installation
Ubuntu 15.04 comes with pre installed git latest version, so don't need to re install it. We can check its version using following command.
git@ubuntu-15:~$ git --version
git version 2.1.4
MySQL Database Installation
In these steps will install mysql server and then create a new database and a user that will serves as Gogs database.
Step 1: Install mysql using apt-get
git@ubuntu-15:~$ sudo apt-get install mysql-server mysql-server-5.6
git@ubuntu-15:~$sudo systemctl status mysql
git@ubuntu-15:~$ sudo mysql --version
mysql Ver 14.14 Distrib 5.6.24, for debian-linux-gnu (x86_64) using EditLine wrapper
Step 2: Choose the root password
During the installation process it will ask for mysql root user password, so choose a secured password.
Step 3: Create New Database and user for Gogs as folowing:
git@ubuntu-15:~$ sudo mysql -u root -p
Enter password:
mysql> SET GLOBAL storage_engine = 'InnoDB';
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> CREATE DATABASE gogs CHARACTER SET utf8 COLLATE utf8_bin;
Query OK, 1 row affected (0.00 sec)mysql> CREATE USER 'gogs'@'localhost' IDENTIFIED by 'gogs123';
Query OK, 0 rows affected (0.00 sec)mysql> GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY 'gogs123';
Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)mysql> \q
Bye
Go Installation
We will install the go(bash) package in a separate directory so that it wouldn't interface with future updates by system's packet manager.
Step 1: Create a new directory and download latest release of Go
git@ubuntu-15:~$ sudo mkdir local
git@ubuntu-15:~$ cd local/
git@ubuntu-15:~/local$ pwd
/home/git/local
git@ubuntu-15:~/local$ sudo wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
Step 2: Expand the package into same ~/local directory
git@ubuntu-15:~/local$ sudo tar xf go1.4.2.linux-amd64.tar.gz
git@ubuntu-15:~/local$ ls
go go1.4.2.linux-amd64.tar.gz
Step 3: Type “go” in the terminal and you will see its command line manual as
Set Up the Environment for Go
Here we need to build an environment for git user to setup its paths that are corresponding to our system.
Gogs Installation Starts
Now we at the point to start the installation of Gogs using the Go source code command line tool.
Step 1:Run the Get command of Go to download Gogs
git@ubuntu-15:~/local$ go get -u github.com/gogits/gogs
Step 2: Change directory and build main program
git@ubuntu-15:~/local$ cd $GOPATH/src/github.com/gogits/gogs
git@ubuntu-15:~/go/src/github.com/gogits/gogs$ go build
Step 3: Gogs Installation Test
Run following command to make sure that gogs is working fine and if you don't see any error message just Press Ctrl-c to stop Gogs, you can also access it on your localhost web browser with your IP and port 3000 but its better not to start the installation at this point to avoid from errors.
git@ubuntu-15:~$ cd $GOPATH/src/github.com/gogits/gogs
git@ubuntu-15:~/go/src/github.com/gogits/gogs$ ./gogs web
Nginx Installation
We need to install Nginx to use it as a reverse proxy so that we can bind our domain name to Gogs.
So lets start with its installation and then we will configure it for Gogs.
Step 1: Install Nginx with apt-get command as
git@ubuntu-15:~$ sudo apt-get install nginx
git@ubuntu-15:~$ sudo systemctl status nginx
git@ubuntu-15:~$ sudo nginx -V
nginx version: nginx/1.6.2 (Ubuntu)
Step 2: Configure Nginx
git@ubuntu-15:~$ sudo vi /etc/nginx/sites-available/default
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;server_name 172.25.10.179;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://localhost:3000;
try_files $uri $uri/ =404;
}
}
Step 3: Now Restart Niginx Service and check its status
git@ubuntu-15:~$ systemctl restart nginx
Gogs as a Service StartUp
To setup Gogs starts automatically as a running service at the back end we are going to do so by installing a package Supervisor.
Step 1: Installing Supervisor with apt-get
git@ubuntu-15:~$ sudo apt-get install supervisor
git@ubuntu-15:~$ systemctl status supervisor
Step 2: Reconfigure Supervisor
After installing supervisor, now configure it as per according to our environment and needs. Lets start with creating a new directory for logs and then append the supervisod.conf file as:
git@ubuntu-15:~$ sudo mkdir -p /var/log/gogs
git@ubuntu-15:~$ sudo vi /etc/supervisor/supervisord.conf[program:gogs]
directory=/home/git/go/src/github.com/gogits/gogs/
command=/home/git/go/src/github.com/gogits/gogs/ web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfilebackups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment = HOME="/home/git", USER="git"
Step 3: Restart Supervisor Service and check its status
Finalize Gogs Installation Setup
Gogs has been been all setup with its initial setting and configurations with other required packages. Now we only need to perform few installation step at its first time run.
Lets Open your web browser and access gogs with your localhost IP as:
http://localhost:3000/install
http://172.25.10.179:3000/install
Choose the appropriate configurations in its database type, user name and Password. Then after creating an admin account just click to Install Gogs, thats it.
Welcome To Gogs
Let's Create Your Repositories
You have created your first repository on Gogs
Gogs Dashboard
Clone Local Repository with SSH
We can also clone any repositories by using its dashboard. We only need to get the desired repository's link and then SSH the other system then by using git clone command we can easily get it on other system.
We can also comment out using git commit and git push commands to pass on our comments on the master repositories.
Conclusion
Gogs is a great git hosting service and much more powerful than Github. Its lightweight, easy to set up, cross-platform git hosting service and with features favorably comparable to Gitlab/Github. So I definitely recommend Gogs as your git self-hosting service.
The post How to Configure Gogs on Ubuntu 15.04 appeared first on LinOxide.