My HP

2nd June, 2017 | Tutorials |

How to Install Gogs on Ubuntu 16.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server

Gogs is a free and open source self-hosted Git service written in the Go programming language. It is very similar to GitLab and aims to be the easiest and most painless way to set up self-hosted Git service in your development environment.

In this tutorial, we will learn how to install Gogs with Apache as a reverse proxy on Ubuntu 16.04 server.

Requirements

Update the System

Before installing any packages, it is recommended to update your system with the latest stable version. You can do this with the following commands:

sudo apt-get update -y sudo apt-get upgrade -y

Once your system is up to date, you can proceed to install the Apache web server.

Install Apache Web Server

First, you will need to install Apache web server on your system. You can easily install it by running the following command:

sudo apt-get install apache2 -y

Once apache is installed, start the Apache web server and enable it to start on boot with the following command:

sudo systemctl start apache2 sudo systemctl enable apache2

Install PHP

You can install PHP and other required modules with the following command:

sudo apt-get install wget unzip php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-mcrypt php7.0-mbstring php7.0-curl php7.0-zip php7.0-gd

Next, enable the Apache2 proxy module with the following command:

sudo a2enmod proxy proxy_http

To activate the new configuration, restart the Apache web server using the following command:

sudo systemctl restart apache2

Once you are done, you can proceed to install MariaDB server.

##Install and Configure MariaDb Server

You will need to install MariaDB server to store data. You can install it with the following command:

sudo apt-get install mariadb-server -y

Start MariaDB and enable it to automatically start at boot time.

sudo systemctl start mysql sudo systemctl enable mysql

By default, MariaDB is not secured, so you will need to secure it first. You can secure it by running the mysql_secure_installation script.

sudo mysql_secure_installation

Answer all the questions as shown below:

Set root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Once MariaDB is secured, log in to the MySQL shell and create a database for Gogs:

mysql -u root -p

Enter your root password when prompt, then create a database for Gogs. It is recommended to set secure password:

MariaDB [(none)]>CREATE DATABASE gogs_db;
Query OK, 1 row affected (0.00 sec)

Next, create a username and password for gogs with the following command:

MariaDB [(none)]>CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
Query OK, 1 row affected (0.00 sec)

Next, grant privileges to the Gogs database with the following command:

MariaDB [(none)]>GRANT ALL PRIVILEGES ON gogs_db.* TO 'user'@'localhost';
Query OK, 1 row affected (0.00 sec)

Next, you will need to run the FLUSH PRIVILEGES command so that the privileges table will be reloaded by MariaDB and we can use new credential:

MariaDB [(none)]>FLUSH PRIVILEGES;
Query OK, 1 row affected (0.00 sec)

Next, exit from the MariaDB console with the following command:

MariaDB [(none)]>\q

Once you are done, you can proceed to the next step.

Configure Apache for Gogs

You will need to create an apache virtual host file for Gogs. You can do this by creating gogs.conf file inside /etc/apache2/sites-available/ directory:

sudo nano /etc/apache2/sites-available/gogs.conf

Add the following lines:

<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html/gogs/
ServerName yourdomain.com
ServerAlias www.yourdomain.com
<Directory /var/www/html/gogs/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ProxyRequests Off
ProxyPass / http://192.168.15.112:3000/
ProxyPassReverse / http://192.168.15.112:3000/
ErrorLog /var/log/apache2/gogs-error_log
CustomLog /var/log/apache2/gogs-access_log common
</VirtualHost>

Save and close the file, then enable virtual host with the following command:

sudo a2ensite gogs.conf

Finally restart Apache web server with the following command:

sudo systemctl restart apache2

Install Gogs

First, you will need to download the latest version of the Gogs. You can download it with the following command:

https://dl.gogs.io/0.11.4/linux_amd64.zip

Once the download is completed, extract the downloaded file with the following command:

unzip linux_amd64.zip

Next, move the extracted directory to the Apache web root directory:

sudo mv gogs /var/www/html/gogs

Next, change the directory to the gogs and run the following command to start gogs:

cd /var/www/html/gogs sudo ./gogs web &

Access Gogs

Before accessing the Gogs Web Interface, you will need to allow port 80 and 3000 through UFW firewall.

By default UFW is disabled on your system, so you need to enable it first. You can enable it with the following command:

sudo ufw enable

Once UFW firewall is enabled, you can allow HTTP service by running the following command:

sudo ufw allow 80/tcp sudo ufw allow 3000/tcp

You can now check the status of UFW firewall by running the following command:

sudo ufw status

Next, Open your web browser and type the URL http://yourdomain.com, you should see the following page:

HP_NO_IMG/data/uploads/users/f36d03b4-5bf0-4986-8e72-2e14d73d9b4d/296014823.png" alt="" />

HP_NO_IMG/data/uploads/users/f36d03b4-5bf0-4986-8e72-2e14d73d9b4d/1159386040.png" alt="" />

Here, provide all the required information like, Database Type, User, Password, Database Name, Application Name, Repository Path, etc. Then click on the Install Gogs button you should see the following page:

HP_NO_IMG/data/uploads/users/f36d03b4-5bf0-4986-8e72-2e14d73d9b4d/477874169.png" alt="" />

Here, click on the Register button to register new account. You should see the following page:

HP_NO_IMG/data/uploads/users/f36d03b4-5bf0-4986-8e72-2e14d73d9b4d/54408157.png" alt="" />

Here, provide your admin user details and click on the Create New Account button. You should see the Gogs login page as below:

HP_NO_IMG/data/uploads/users/f36d03b4-5bf0-4986-8e72-2e14d73d9b4d/1692866098.png" alt="" />

Now, provide the username and password, then click on the Sign In button. You should see the Gogs default Dashboard in following image:

HP_NO_IMG/data/uploads/users/f36d03b4-5bf0-4986-8e72-2e14d73d9b4d/627423245.png" alt="" />

Congratulations! You have seccessfully installed Gogs on your Ubuntu 16.04 server.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.

Get a Cloud Server

Comments