How to Self-Host Gitea on a VPS (Complete Guide)
Gitea is a lightweight, self-hosted Git service that allows developers to manage their projects with ease. In this guide, we will walk through the steps to self-host Gitea on a Virtual Private Server (VPS) using Docker. This setup gives you control over your source code management while keeping costs low.
Choosing a VPS Provider
When selecting a VPS for running Gitea, consider factors like performance, cost, and reliability. Below is a comparison of popular VPS providers that are suitable for self-hosting applications like Gitea:
| Provider | Starting Price | CPU | RAM | Storage |
|---|---|---|---|---|
| Contabo VPS | 5.99 EUR/mo | 2 vCPU | 4 GB | 500 GB SSD |
| Hetzner Cloud | 4.15 EUR/mo | 1 vCPU | 2 GB | 20 GB SSD |
| DigitalOcean | 6 USD/mo | 1 vCPU | 1 GB | 25 GB SSD |
| Vultr | 6 USD/mo | 1 vCPU | 1 GB | 25 GB SSD |
| Linode (Akamai Cloud) | 5 USD/mo | 1 vCPU | 1 GB | 25 GB SSD |
For Gitea, even a low-spec VPS will suffice, although you may want to consider a provider with better uptime and customer support, such as Contabo or Hetzner.
Prerequisites
Before we begin the installation, ensure you have the following:
- A VPS instance running a Linux distribution (Ubuntu is recommended).
- Root access to your VPS.
- Docker and Docker Compose installed on your server. If they are not installed, follow the steps below:
Install Docker and Docker Compose
-
Connect to your VPS via SSH:
ssh root@your_vps_ip -
Update your package index:
apt update && apt upgrade -y -
Install Docker:
apt install -y docker.io -
Enable and start Docker:
systemctl enable docker systemctl start docker -
Install Docker Compose:
apt install -y docker-compose
Installing Gitea with Docker
Now that Docker is installed, we can proceed to deploy Gitea.
-
Create a directory for Gitea:
mkdir -p /opt/gitea cd /opt/gitea -
Create a Docker Compose file named
docker-compose.yml:version: '3' services: gitea: image: gitea/gitea:latest environment: - USER=git - GITEA__database__DB_TYPE=sqlite3 - GITEA__database__PATH=/data/gitea.db - GITEA__server__DOMAIN=yourdomain.com - GITEA__server__ROOT_URL=https://yourdomain.com - GITEA__server__HTTP_PORT=3000 - GITEA__server__SSH_PORT=22 - GITEA__security__INSTALL_LOCK=true volumes: - gitea_data:/data ports: - "3000:3000" - "222:22" volumes: gitea_data: -
Replace
yourdomain.comwith your actual domain name or the IP address of your VPS. -
Start the Gitea service:
docker-compose up -d -
Check if Gitea is running:
docker ps
Configuring Gitea
After starting Gitea, you can access it in your web browser by entering http://your_vps_ip:3000 or http://yourdomain.com:3000. The initial setup will guide you through configuring the database and admin account.
Steps to Configure:
-
Database: Since we are using SQLite, you can keep the default settings.
-
Application URL: Set this to your domain or IP.
-
Admin Account: Create the admin user account.
-
Additional Settings: Configure email notifications and other features according to your needs.
Managing Gitea
Once Gitea is installed and configured, you can manage it through the web interface. You can create repositories, manage access controls, and utilize the various features offered by Gitea.
FAQs
1. Can I use Gitea for private repositories?
Yes, Gitea allows you to create private repositories where only invited collaborators can access the code. This is perfect for teams working on proprietary projects or sensitive code.
2. How secure is Gitea when self-hosting?
Security largely depends on your serverโs configuration. Ensure your firewall is configured, keep your software updated, and consider using HTTPS for secure connections. Regular backups of your data are also a good practice.
3. Can I migrate my projects from GitHub to Gitea?
Yes, Gitea provides built-in tools to import repositories from GitHub and other services. Simply follow the import tools in the Gitea web UI and provide the necessary repository URLs and authentication tokens.
Conclusion
Self-hosting Gitea on a VPS is a straightforward process that provides you with flexibility and control over your code repositories. The Docker deployment method ensures easy setup, scalability, and management of your Gitea instance. For a comprehensive view of different VPS options to host your applications, check out our full VPS comparison. Happy coding!