Are you looking for a self-hosted Git service that is simple, stable, and extensible? Look no further than Gogs! In this step-by-step guide, we will walk you through the process of installing Gogs Git on a RockyLinux 8 server. Gogs, written in Go, is renowned for its lightweight nature, using minimal RAM and CPU power. Let’s dive in and get started!
Prerequisites
Before we begin, ensure that you have full SSH root access or a user with sudo privileges. Additionally, Gogs supports the following databases:
- SQLite3
- PostgreSQL
- MySQL
- MariaDB
Step 1: Checking for System Upgrades
It’s always a good idea to start by checking for any pending system upgrades. To do this, run the following command:
dnf update
Step 2: Installing MariaDB Database Server
Next, we need to install the MariaDB database server. Use the following command to install MariaDB:
dnf install mariadb-server
Once installed, start the MariaDB service:
systemctl start mariadb
To ensure that MariaDB starts on boot, enable it with the following command:
systemctl enable mariadb
Check the status of the MariaDB service to confirm that it is running:
systemctl status mariadb
Step 3: Securing the Mysql Installation
To secure the MySQL installation, run the following command:
mysql_secure_installation
This command will prompt you to set the root password for MariaDB, ensuring that only authorized users can access it.
Step 4: Creating a Database and User for Gogs
Now, let’s create a database and user specifically for the Gogs project. Start by logging in to MySQL as the root user:
mysql -u root -p
Once logged in, execute the following command to enable global variables:
SET GLOBAL innodb_file_per_table = ON;
Next, create a database called “gogs” using the following command:
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
After creating the database, create a user and grant all privileges on the “gogs” database:
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY "StrongPassword";
Remember to replace “StrongPassword” with a strong and secure password.
To apply the changes, flush the privileges and exit MySQL:
FLUSHP RIVILEGES; EXIT;
Step 5: Downloading and Installing Gogs from GitHub
It’s time to download and install Gogs from the official GitHub repository. Use the following command to download the Gogs file:
curl -s https://api.github.com/repos/gogs/gogs/releases/latest | grep browser_download_url | grep '\linux_amd64.zip' | cut -d '"' -f 4 | wget -i -
Once the download is complete, unzip the Gogs file:
unzip gogs_*_linux_amd64.zip
Step 6: Installing Git Packages
Before we proceed, let’s install the necessary Git packages using the dnf command:
dnf install git
Step 7: Creating a Git User and Directory
To ensure proper permissions and organization, it’s best to create a dedicated user and directory for Gogs. Start by creating a new user called “git”:
adduser git
Next, create a directory for the Gogs logs:
mkdir /var/log/gogs
Grant the user access to the logs directory:
chown -R git:git /var/log/gogs/
Move the Gogs binary file to the user’s home directory:
mv gogs/home/git/
Change the ownership of the Gogs directory to the git user:
chown -R git:git /home/git/gogs/
Step 8: Configuring the Firewall for Gogs
To ensure that Gogs is accessible, we need to configure the firewall to allow traffic on port 3001. Use the following commands:
firewall-cmd --zone=public --add-port=3001/tcp --permanent firewall-cmd --reload
Step 9: Running Gogs
Switch to the git user we created earlier:
su - git
Change the directory to where Gogs is located:
cd /home/git/gogs/
Finally, run Gogs with the web option on port 3001:
./gogs web-port 3001
Step 10: Configuring Gogs
Open your browser and enter the server’s IP address or domain name followed by port 3001 (e.g., http://server-ip-address:3001). This will bring up the Gogs installation screen.
Database Settings
In the database settings, enter the information for the database you created earlier.
Application General Settings
In the application general settings, provide the following information:
- Application Name: Choose a name for your project.
- Run User: Select the newly created “git” user.
- Domain: Enter the domain name associated with the application.
- Application URL: Enter the IP address or domain name with the port to be used.
- Log Path: Specify the directory path for the Gogs logs.
Optional Settings
Enable or disable any additional settings based on your application’s requirements.
Creating an Admin Account
Create an admin account that you will use to log in to Gogs.
Click on the “Install Gogs” button to start the installation process.
Step 11: Logging In to Gogs
Once the installation is complete, you will be redirected to the login screen. Log in with the admin account you created in the previous step.
Congratulations! You have successfully installed and configured Gogs Git on your RockyLinux 8 server. Now you can enjoy the benefits of a self-hosted Git service.
Conclusion
Gogs is a lightweight and reliable self-hosted Git service written in Go. By following this comprehensive guide, you have learned how to install Gogs on a RockyLinux 8 server. Remember to secure your installation, create a dedicated user and directory, configure the firewall, and customize the Gogs settings to fit your needs.
For efficient, scalable, and secure cloud hosting solutions, consider Shape.host. Shape.host offers Cloud VPS services that cater to the needs of businesses requiring reliable infrastructure. Experience the power of Shape.host and elevate your hosting experience.