How to Self-Host Forgejo on a VPS (Complete Guide)
Forgejo is a powerful, open-source self-hosted Git service that provides a seamless experience for managing your projects and repositories. Deploying it on a Virtual Private Server (VPS) allows you to maintain full control over your data and customize your environment. This guide walks you through the steps required to self-host Forgejo on a VPS, covering everything from installation to configuration.
Prerequisites
Before you begin, make sure you have the following:
- A VPS with at least 1GB of RAM and 1 CPU core
- A domain name pointed to your VPS (optional but recommended)
- Docker and Docker Compose installed on your VPS
- Basic knowledge of Linux command line
Choosing a VPS Provider
When selecting a VPS provider, consider factors like performance, price, and support. Below is a comparison of some top VPS providers suitable for hosting Forgejo:
| Provider | Price (per month) | RAM | Storage | Data Centers |
|---|---|---|---|---|
| Contabo VPS | 5.99 EUR | 4 GB | 200 GB | Europe |
| Hetzner Cloud | 4.15 EUR | 2 GB | 20 GB | Europe |
| DigitalOcean | 6 USD | 1 GB | 25 GB | Global |
| Vultr | 6 USD | 1 GB | 25 GB | Global |
| Linode (Akamai Cloud) | 5 USD | 1 GB | 25 GB | Global |
All prices are competitive and provide a solid foundation for self-hosting applications like Forgejo. Check out our full VPS comparison for more options.
Step 1: Setting Up Your VPS
-
Access Your VPS: Use SSH to log in to your VPS.
ssh root@your_server_ip -
Update the System: Ensure your VPS is up to date.
apt update && apt upgrade -y -
Install Docker and Docker Compose:
apt install docker.io docker-compose -y -
Start Docker Service:
systemctl start docker systemctl enable docker
Step 2: Deploying Forgejo with Docker
-
Create a Directory for Forgejo:
mkdir -p /opt/forgejo cd /opt/forgejo -
Create the
docker-compose.ymlFile:Use your preferred text editor to create the file.
nano docker-compose.ymlAdd the following content:
version: '3' services: forgejo: image: forgejo/forgejo:latest environment: - GITEA__database__DB_TYPE=sqlite3 - GITEA__database__PATH=/data/gitea/gitea.db - GITEA__server__DOMAIN=yourdomain.com - GITEA__server__ROOT_URL=https://yourdomain.com volumes: - ./data:/data ports: - "3000:3000" - "22:22" restart: unless-stoppedAdjust the
DOMAINandROOT_URLto your actual domain name. -
Start Forgejo:
docker-compose up -d
Step 3: Accessing Forgejo
After the container starts, you can access Forgejo by navigating to http://yourdomain.com:3000 in your web browser. Complete the initial setup, including admin account creation.
Optional: Setting Up Reverse Proxy
For better security and SSL support, itโs recommended to set up a reverse proxy. You can use NGINX or Traefik for this purpose. Below is a simple NGINX configuration example:
-
Install NGINX:
apt install nginx -y -
Create NGINX Configuration:
nano /etc/nginx/sites-available/forgejoAdd the following:
server { listen 80; server_name yourdomain.com; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } -
Enable Configuration:
ln -s /etc/nginx/sites-available/forgejo /etc/nginx/sites-enabled/ nginx -t systemctl restart nginx
FAQs
1. How secure is self-hosting Forgejo on a VPS?
Self-hosting Forgejo on a VPS can be secure, provided you follow best practices such as regularly updating your software, using strong passwords, and setting up firewalls. Ensure that your VPS provider offers DDoS protection and choose a data center location that suits your latency and security needs. Additionally, secure your Forgejo instance with HTTPS to encrypt data in transit. Check the security practices outlined in forums like r/selfhosted for more detailed recommendations.
2. Can I customize Forgejo features?
Yes, Forgejo is highly customizable. You can modify its settings via the administration panel to tailor it to your needs. Forgejo supports various authentication methods, repository permissions, and much more. Explore the official Forgejo documentation for comprehensive customization instructions and learn how to integrate it with CI/CD tools for enhanced productivity.
3. What if I encounter issues during installation?
If you face issues during the installation or configuration of Forgejo, consider searching through community forums such as r/selfhosted and GitHub issues. Additionally, ensure that Docker and Docker Compose versions are up to date as compatibility can sometimes cause issues. The Forgejo GitHub repository also contains valuable information and user support, making it a useful resource for troubleshooting.
By following this guide, you should now have a fully functional Forgejo instance running on your VPS. Happy coding and self-hosting!