How to Install and Configure Gitea on VPS for Git Hosting

Gitea is a lightweight, self-hosted Git service that allows developers to manage their Git repositories with ease. It provides a web interface similar to GitHub, Bitbucket, and GitLab, making it an excellent option for setting up your own Git hosting service. In this guide, we’ll walk you through the steps to install and configure Gitea on a VPS for hosting your Git repositories.


Prerequisites

Before you start, ensure the following:

  • A VPS running Ubuntu 20.04 or any other supported Linux distribution.
  • Root or sudo privileges to install software and configure system settings.
  • A domain name or public IP address to access your Gitea server remotely.
  • A firewall (optional) to restrict access and secure your VPS.

Step 1: Update Your VPS

Start by updating your VPS to make sure all system packages are up to date. This ensures that you're using the latest, secure versions of your packages.

 
sudo apt update && sudo apt upgrade -y

Step 2: Install Dependencies

Gitea has some dependencies, including git, sqlite3 (for local database storage), and curl. Install them by running the following commands:

 
sudo apt install git sqlite3 curl -y

Step 3: Create a Gitea User

For security purposes, it’s a good practice to create a separate user to run Gitea instead of using the root user. Create the gitea user and assign it appropriate permissions.

 
sudo useradd --create-home --shell /bin/bash --system --group gitea

Step 4: Install Gitea

Gitea provides precompiled binaries for easy installation. To install it, you can download the binary from the official Gitea releases page.

  1. Download the Gitea binary:

    Visit the official Gitea GitHub releases page to find the latest stable release:
    https://github.com/go-gitea/gitea/releases

    You can download it using wget:

     
    wget -O /tmp/gitea https://dl.gitea.io/gitea/<version>/gitea-<version>-linux-amd64

    Replace <version> with the actual version number you want to install.

  2. Move the Gitea binary to the appropriate location:

    After downloading the binary, move it to /usr/local/bin/:

     
    sudo mv /tmp/gitea /usr/local/bin/gitea
  3. Make the binary executable:

     
    sudo chmod +x /usr/local/bin/gitea

Step 5: Configure Gitea as a Service

To ensure that Gitea starts automatically on boot and runs as a background service, you can create a systemd service.

  1. Create a systemd service file:

     
    sudo nano /etc/systemd/system/gitea.service
  2. Add the following content to the file:

    ini
     
    [Unit] Description=Gitea: Git with a cup of tea Documentation=https://docs.gitea.io After=network.target [Service] User=gitea Group=gitea Type=simple ExecStart=/usr/local/bin/gitea web WorkingDirectory=/home/gitea Restart=always Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/home/gitea/.gitea [Install] WantedBy=multi-user.target
  3. Reload the systemd service manager to apply the changes:

     
    sudo systemctl daemon-reload
  4. Enable Gitea to start on boot:

     
    sudo systemctl enable gitea
  5. Start the Gitea service:

     
    sudo systemctl start gitea

Step 6: Open Ports in the Firewall (Optional)

If you have a firewall enabled on your VPS, you need to allow HTTP and HTTPS traffic to access Gitea.

  1. Allow HTTP (port 3000) and HTTPS (port 443) traffic if you're using a firewall like UFW:

     
    sudo ufw allow 3000/tcp sudo ufw allow 443/tcp
  2. Enable UFW if it is not already enabled:

     
    sudo ufw enable
  3. Check UFW status to confirm the rules are applied:

     
    sudo ufw status

Step 7: Access Gitea Web Interface

Once the Gitea service is up and running, you can access it through a web browser by navigating to your VPS's IP address or domain name, followed by port 3000. For example:

arduino
 
http://your_vps_ip:3000

Or, if you have a domain configured:

arduino
 
http://your_domain.com:3000

Step 8: Complete the Web Installer

The first time you access Gitea, you'll be prompted to complete the initial configuration through the web interface.

  1. Choose the database type. For simplicity, you can use the default SQLite3 database.

  2. Set the server URL to your VPS's IP address or domain name:

    • Application URL: http://your_vps_ip:3000 (or your domain name).
    • Repository Root Path: /home/gitea/gitea-repositories (default path for repository storage).
  3. Create an admin account by entering your desired username, password, and email address.

  4. Click "Install Gitea" to complete the installation process.


Step 9: Access Your Gitea Dashboard

Once the installation is complete, you can log in to the Gitea web interface using the admin credentials you just created. From there, you can start creating and managing Git repositories, as well as configuring settings for users, teams, and more.


Step 10: Set Up SSL for Secure Access (Optional)

To ensure secure connections, it’s highly recommended to configure SSL (HTTPS) for your Gitea server. You can use Let’s Encrypt for a free SSL certificate.

  1. Install Certbot for obtaining and managing SSL certificates:

     
    sudo apt install certbot python3-certbot-nginx -y
  2. Request an SSL certificate for your domain:

     
    sudo certbot --nginx -d your_domain.com

    Follow the prompts to complete the SSL setup.

  3. Test the SSL setup by visiting https://your_domain.com in your browser.


Step 11: Configure Backups (Optional)

It's essential to back up your Gitea server to avoid data loss. You can create regular backups of the repository database and configuration files.

  1. Backup Gitea repositories:

    Use the following command to back up Gitea repositories:

     
    tar -czvf gitea_repositories_backup.tar.gz /home/gitea/gitea-repositories/
  2. Backup Gitea configuration:

    Back up the configuration file, which is located at /home/gitea/.gitea.


Conclusion

You have successfully installed and configured Gitea on your VPS for Git hosting. With Gitea, you now have a self-hosted Git service that you can use for managing repositories and collaborating with your team. Remember to secure your Gitea server with SSL and consider setting up regular backups to protect your data.

Feel free to explore more advanced features of Gitea, such as integrating webhooks, managing multiple repositories, and configuring LDAP authentication for enterprise environments.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution