Gogs is a self-hosted git service, similar to Gitlab. It is written in Go and requires much less hardware compared to Gitlab. The goal of Gogs is to provide the easiest, fastest, and most painless way of setting up a self-hosted Git service. As this application is written in Go, it supports all platforms like Linux, Windows, OS X and ARM.
Features of Gogs:
Easy to install and supports multiple platforms.
Minimum hardware requirement.
It is completely free and open source.
Supports SSH and HTTP/HTTPS protocols.
Supports multiple authentication protocols.
Mail service and Administration panel.
Repository web-hooks and Git hooks.
Repository issues, pull requests and wiki supports web editor for repository files and wiki.
Supports MySQL, PostgreSQL, SQLite3 and TiDB.
Gogs supports many operating systems but in this tutorial we are going to install Gogs in CentOS 7.x.
VPS, Cloud or Dedicated Server running CentOS 7.x
A Simple Raspberry Pi board is enough to support basic functionality.
Recommended configuration would be a 2 core CPU and at least 1 GB RAM.
Apart from this we will need to install all the required dependencies in the tutorial. Additionally you can always increase the CPU cores and memory to add support for more users.
You can use the IP address of your server to install and set up Gogs, but it is recommended to use a FQDN. In this tutorial we will be using git.example.com. To use a domain name with Gogs, make necessary DNS changes to point your domain or subdomain to the IP address of your server. You will also need root access to your server. If you are logged in as non root user, run sudo -i to switch as root user.
Gogs requires few dependencies in order to work, which are an SQL server, git and SSH server. We can use either MySQL or PostgreSQL server as SQL server. It also supports SQLite but SQLite is not recommended for production use. In this tutorial we will be installing MySQL.
Before installing any package it is recommended to update your system and packages. Run the following command to update your system.
yum -y update
Now setup the hostname for your server. For the ease of identification, you may want it to be same as your domain name.
hostnamectl set-hostname git.example.com
You can replace git.example.com with anything you want. You will also need to disable your SELinux. Run the following command to do so.
sed -i /etc/selinux/config -r -e 's/^SELINUX=.*/SELINUX=disabled/g'
You will need to reboot your server for SELinux changes to take effect. Run systemctl reboot to reboot your server.
Install and setup MySQL
MySQL does not comes with the default YUM repository of CentOS, hence you will need to add the MySQL repository in your server. The following commands will add MySQL repositories in your server.
Now install MySQL server on your machine using the following command.
yum -y install mysql-server
Now start MySQL server and enable it to automatically start at boot time using following commands.
systemctl start mysqld
systemctl enable mysqld
During installation the root user of MySQL is assigned a random password. To fetch the password run the following command.
grep 'temporary password' /var/log/mysqld.log
You will see an output similar to the one shown below. The output should contain your temporary root password.
[root@git ~]# grep 'temporary password' /var/log/mysqld.log
2016-09-10T07:24:29.105209Z 1 [Note] A temporary password is generated for root@localhost: i,DtiXeP!1EG
Now you will need to secure your MySQL installation using the following command.
You will be asked for your MySQL root password. Enter your temporary password. Once logged in, change the password for root user. You will be prompted with few more questions. Recommended is that you answer y for all questions. The output will look like shown below.
[root@git ~]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : Y
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
- Removing privileges on test database...
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Now login to your MySQL command line using the following command and providing your new MySQL root password.
mysql -u root -p
Then execute the following queries in MySQL command line.
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci;
You will see following output for these commands.
[root@git ~]# mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 14
Server version: 5.7.15 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
mysql> use gogs;
mysql> SET default_storage_engine=INNODB;
Query OK, 0 rows affected (0.00 sec)
As we have our database ready, we can now move to next step.
Gogs required to git for version control, you can get git using the following command.
yum -y install git
You can check your Git version using the following command.
You should get similar output.
[root@git ~]# git --version
git version 126.96.36.199
You can install Gogs in many different ways but the easiest way to install Gogs is using Packager Repository. Run the following commands to add Packager.io Gogs repository in your server.
rpm --import https://rpm.packager.io/key
name=Repository for pkgr/gogs application.
enabled=1" | tee /etc/yum.repos.d/gogs.repo
Now you can install Gogs, using the following command.
yum -y install gogs
Once the installation finishes you can starts Gogs using the following command.
systemctl start gogs
To enable Gogs to start at boot time, run the following command.
systemctl enable gogs
To check the status of Gogs service, run the following command.
systemctl status gogs
If service is running you will get output similar to shown below.
[root@git ~]# systemctl status gogs
Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2016-09-10 08:34:53 UTC; 6min ago
Main PID: 5760 (sleep)
â””â”€5760 /bin/sleep infinity
By default Gogs service runs on port 3000, you can access the web installer for Gogs on http://your-server-IP:3000 or http://Your-Domain.com:3000. Please do not make any changes to this page as we are going to run nginx as the reverse proxied web server, and Gogs web server will run behind the scenes.
Install and Configure Nginx
Nginx does not come with the default YUM repository, hence you will need to add EPEL repository to your server. Run the following command to do so.
yum -y install epel-release
yum -y update
yum clean all
Now you can install nginx using the following command.
yum -y install nginx
Now start nginx and enable it start at boot time using the following command.
systemctl start nginx
systemctl enable nginx
Now you will need to create a virtual host file for your nginx reverse proxy.
Replace your_domain_or_server_ip with your domain or the server IP. You can also put your domain name and IP address both, separated by a space to enable the access using both domain name and IP address.
Now restart your nginx server using the following command.
systemctl restart nginx
Now you will be able to access the site by browsing the following URL using your favorite browser. If you are using your domain name name then your site is accessible on http://your.domain.com if you are using IP address, then it will be accessable on http://your-IP-address
If you wish to use HTTPS instead of Plain HTTP, you can either generate a self signed certificate or purchase a commercial SSL certificate. You can also use Certbot or Let's Encrypt SSL to generate free SSL for your domain.
Download Certbot script using the following command.
Replace git.example.com with your domain name. To generate SSL for your domain, you must have the DNS configured which points your domain to the IP address of the server. If you do not have your domain configured, you can stay with HTTP also.
You will be asked to enter your email address and accept the terms and conditions. Finally you will see message similar to this.
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/git.example.com/fullchain.pem. Your cert
will expire on 2016-12-09. To obtain a new or tweaked version of
this certificate in the future, simply run certbot-auto again. To
non-interactively renew *all* of your certificates, run
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Once done you can configure nginx to use SSL certificates by editing the virtual host configuration file using the following command.
Now replace the existing contents with the new content shown below.
return 302 https://$server_name$request_uri;
listen 443 ssl;
In Database Setting choose the database type, in this case it will be MySQL. The host should not be changed, and as we have used root user to create MySQL database, the user should be root. Enter the password of your MySQL root user. Database name should also be left as gogs.
In Application General Settings, provide a name for your Application, you can give the name of your organisation. Provide a path for your repositories. You can choose to leave it as it is or you can also change the path as required. Make sure that the directory is under Gogs home directory which is /home/gogs/. All the git remote repositories will be saved here.
In Run As option choose the user which runs Gogs, also has access to the repository root path. In our case, it should be left as gogs. Now provide the domain name for your repository. This domain name will be used when cloning via SSH. Do not include http:// or www in this domain name. Provide a port for SSH, it should be left as 22 unless changed. Provide a port on which the application will listen, it should be left as 3000. Now provide the HTTP Application url of your Git server. It should be in https://git.example.com format. Choose a path to store the logs.
Furthermore you can configure the SMTP settings to that Gogs can send email notification to the user. If you do not have SMTP credentials you can skip this configuration.
In Admin Account Settings, provide a username for administrator, it must be something other than admin. Provide the password for the administrator account twice and provide a email for admin account.
From the dashboard you can create a new file or upload an existing file into the repository. You can also edit the files using the web based interface by clicking on the name of the file.
In this tutorial we have learnt to install Gogs on CentOS 7.x, You can now easily host a private Git repository on your server even if do not have huge resources. You can also easily create repositories and collaborate with others. If you want more features then Gogs provides, you can install GitLab on your CentOS server.
You can create an email email filters through your cPanel control panel which is where you manage your hosting account. Email filters can be set up to target specific word, subject, from or to. Emails that are filtered out can be sent to a different email, deleted, delivered to a...
If you find your cPanel disk space filling up, or an email address has hit its disk space quota, cPanel has a helpful built in Email Disk Usage tool. This will provide you with a simple to understand breakdown of how much disk space each folder for a particular email...
Although WHM will normally automatically keep itself up to date, you may want to manually check for server updates / push through an update that is pending, or it may be that you have automatic updates switched off on your cPanel server. In this guide we will show you how...