In this guide, we will show you how to install Gogs on a CentOS 7 VPS with MariaDB as a backend database.
Gogs is a free and open-source self-hosted Git service written in the Go programming language. It’s easy-to-install, cross-platform, and lightweight, all of which allows Gogs to run on all sorts of hardware easily. This guide should work on other Linux VPS systems as well, but it was tested and written for CentOS 7. Let’s get started with the installation.
Table of Contents
Prerequisites:
- A Server running CentOS 7
- A user account with sudo privileges, or access to the ‘root’ user itself
Step 1: Install Required packages
Log in to your VPS via SSH as the root account or as a sudo user:
Replace IP_Address and Port_Number with your server’s respective IP address and SSH port number.
Once logged in, run the following commands to update all packages to their latest available versions:
Next, we need to install git. You can do that by using the following command:
Step 2: Create a MariaDB database
Gogs can use MySQL/MariaDB, PostgreSQL, MSSQL, TiDB, and SQLite3 databases as a database backend.
In this tutorial, we will use MariaDB. To install the latest MariaDB server execute the following command:
When the MariaDB installation is complete, secure your MariaDB server using the mysql_secure_installation
script. This part is optional, but strongly recommended as it improves the security of your database server:
Then, answer the security questions as follows. If the program asks for a MySQL root password before you have set it, press the [Enter] key, as the default root password is blank by default:
Log in to the MariaDB console with the MariaDB root user, using the password that you have set up in the previous step:
Create a MariaDB database and user for Gogs, and grant permissions to the user using the following commands:
Don’t forget to replace ‘strongpassword‘ with an actual strong password.
Step 3: Install Gogs
First, create a new system user for Gogs:
Download the Gogs binary from the Gogs Github page using the following command (We’ve pre-inserted the link for the current latest version for you):
When the download is complete, extract the archive to the /opt/gogs
directory:
Change the ownership of the extracted directory to the Gogs user:
Next, copy the systemd unit file:
Open the unit file using your preferred text editor – we use nano.
Once the file is open, edit it as follows:
Save and close the file, then reload the systemd units:
Finally, start and enable the Gogs service:
Verify that the Gogs service is started successfully:
Step 4: Set Up Gogs
Once the installation is complete, go to http://server_ip:3000/install
and fill in all of the required fields:
Database Settings
– Database Type: MySQL
– Host: 127.0.0.1:3306
– User: gogs
– Password: strongpassword
– Database Name: gogs
General Settings of Gogs
– Application Name: Gogs
– Repository Root Path: /opt/gogs/gogs-repositories
– Run User: gogs
– Domain: SERVER_IP
– SSH Port: 22
– HTTP Port: 3000
– Application URL: http://SERVER_IP:3000/
– Log Path: /opt/gogs/log
Do not forget to replace “SERVER_IP” with your server’s public IP address.
Finally, click install and you’re good to go.
NOTE: Administrative access is automatically granted to the first registered user.
That’s it. You have successfully installed Gogs on your CentOS 7 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 or CentOS VPS Hosting services, in which case you can simply ask our expert Linux admins to set all of this up for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post, please share it with your friends on the social networks using the share shortcuts below, or simply leave a comment down in the comments section. Thanks.