🚀 Host Your Own Git Server: Gitea on AWS EC2 (Ubuntu)

"Because sometimes you just need to git your own way!"

Tired of GitHub's limits? Want a lightweight, self-hosted Git solution that gives you complete control? Let's deploy Gitea - the painless Git service - on an AWS EC2 instance and break free from the constraints of commercial Git platforms.

Gitea Dashboard
The clean, intuitive Gitea dashboard you'll have after following this guide

🧰 What You'll Need

Required

  • An AWS account (free tier works perfectly)
  • Basic terminal/SSH knowledge
  • About 30 minutes of your time
  • A cup of coffee (optional but recommended)

Nice to Have

  • A domain name for your Gitea instance
  • SSL certificate (Let's Encrypt works great)
  • Previous experience with Linux administration

Why Gitea?

Gitea is a lightweight, open-source Git service written in Go. It's designed to be the easiest, fastest, and most painless way to set up a self-hosted Git service. With minimal system requirements and a simple setup process, it's perfect for personal use or small teams.

🚀 Chapter 1: Launching Your EC2 Instance

First, we need to set up our AWS EC2 instance. I'll walk you through the process step by step:

AWS Console Setup
# Launch Instance Configuration
AMI: Ubuntu 22.04 LTS
Type: t2.micro (free tier eligible)
Storage: 8GB gp2 (minimum)
Security Group:
  - SSH (Port 22) from your IP
  - HTTP (Port 80) from anywhere
  - HTTPS (Port 443) from anywhere
  - Custom TCP (Port 3000) from anywhere

Security Note: For production, restrict access to only necessary IPs. The above configuration is for initial setup and testing.

EC2 Security Groups Configuration
EC2 Security Groups configuration for Gitea
SSH Connection
# Connect to your instance
ssh -i "your-key.pem" [email protected]

# Update system packages
sudo apt update && sudo apt upgrade -y

⚙️ Chapter 2: Installing Gitea and Dependencies

Now that we have our EC2 instance up and running, let's install Gitea and its dependencies:

System Dependencies
# Install required packages
sudo apt install -y git nginx mysql-server

# Create a dedicated user for Gitea
sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git

Why these packages?

  • git: Core requirement for any Git server
  • nginx: Web server to act as a reverse proxy
  • mysql-server: Database for storing Gitea data
MySQL Setup
# Secure MySQL installation
sudo mysql_secure_installation

# Create database and user for Gitea
sudo mysql -u root -p

CREATE DATABASE gitea;
CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'strong-password';
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Security Tip: Use a strong, unique password for the MySQL user. Store it securely as you'll need it during Gitea configuration.

Gitea Installation
# Download the latest Gitea binary
wget -O gitea https://dl.gitea.com/gitea/1.20.0/gitea-1.20.0-linux-amd64
chmod +x gitea
sudo mv gitea /usr/local/bin/

# Create required directories
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea
sudo chmod -R 750 /var/lib/gitea
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

🔧 Chapter 3: Configuration and Setup

With Gitea installed, let's configure it to run as a service and set up Nginx as a reverse proxy:

Gitea Service
# Create systemd service file
sudo tee /etc/systemd/system/gitea.service > /dev/null <# Enable and start the service
sudo systemctl enable gitea
sudo systemctl start gitea
Nginx Configuration
# Create Nginx config file
sudo tee /etc/nginx/sites-available/gitea > /dev/null <# Enable the site and restart Nginx
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t  # Test configuration
sudo systemctl restart nginx

Domain Setup: Replace your-domain.com with your actual domain name or the public IP of your EC2 instance if you don't have a domain.

~3000 Default Gitea Port
~50MB RAM Usage
~100MB Disk Space

🛡️ Chapter 4: Maintenance & Security

Automated Updates
# Update script for Gitea
sudo tee /usr/local/bin/update-gitea.sh > /dev/null <
        
Firewall Setup
# Configure UFW firewall
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
Backup Script
# Gitea backup automation
sudo tee /usr/local/bin/backup-gitea.sh > /dev/null < \$BACKUP_DIR/gitea_db_\$TIMESTAMP.sql
sudo tar -czf \$BACKUP_DIR/gitea_data_\$TIMESTAMP.tar.gz /var/lib/gitea /etc/gitea
find \$BACKUP_DIR -name "*.sql" -mtime +30 -delete
find \$BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete
EOF
"Automation is the key to maintenance sanity - set it and forget it!"

🔍 Chapter 5: Troubleshooting Common Issues

Common Problems & Solutions

🔴 502 Bad Gateway Error

Possible causes:
1. Gitea service not running
2. Nginx misconfiguration
3. Port conflict

Diagnosis:
sudo systemctl status gitea
sudo journalctl -u gitea --since "10 minutes ago"

🟡 Database Connection Issues

Check MySQL credentials in:
/etc/gitea/app.ini

Test connection:
mysql -u gitea -p -D gitea

🔵 SSH Clone Problems

Verify permissions:
sudo chown -R git:git /home/git/.ssh

Check auth log:
tail -f /var/log/auth.log

Ready to Host Your Own Git Server?

Follow this guide to set up your own Gitea instance and take control of your Git repositories. No more limits, no more restrictions - just pure Git freedom!

Warning: May cause severe independence from GitHub