Coding
Blogging about computer programming


Note: Running your own server costs money. Not like, a ton. (Well, depending on what you’re doing, but in this case, not a ton.) But you will need to buy 1) a domain name and 2) a computer. Probably a virtual computer, but those are still usually not free. Once you have accepted this into your heart, let us proceed without further ado.

Steps

  • Get a linux machine with the latest version of Ubuntu installed. I used a DigitalOcean droplet (just the basic, cheapest one is fine).
  • Set up a non-root user
  • Get a domain name — I use Namecheap, but it’s your call
  • If you are using DigitalOcean: add your domain to your DigitalOcean account
    • Otherwise, reference your domain provider’s documentation to find out how to manage DNS records for your domain
  • Create a DNS Record for your gitea page
    • Above instructions are DigitalOcean specific, but should give you an idea of how to proceed regardless of how you have chosen to manage your domain
    • You will want to create an “A” record pointed to your machine’s IP address. In this example I have used the subdomain “gitea” but you can use “git” or “myawesomeversioncontrol” or whatever you like.

      Note about IP addresses: this guide assumes you have a static IP address for the machine you’re installing gitea on. If you’re using a physical computer at home, this is likely not the case. Addressing that problem is outside the scope of this guide.

  • Log into your machine with your non-root user account and run the following commands:
    • sudo apt update && sudo apt upgrade
      • Standard command to ensure your installation is up to date
    • sudo snap install gitea
      • Install gitea snap package
    • sudo apt install nginx
      • Install nginx reverse proxy
    • sudo ufw allow "Nginx Full"
      • This allows connections to gitea through your firewall. You should have enabled UFW earlier in the “Set up a non-root user” step. If not, make sure you do that now.
    • sudo nano /etc/nginx/sites-available/gitea
      • This is the configuration that tells nginx how to serve your gitea page. Paste the following into this file (changing the server_name value as specified) and save it:
          server {
          	# Make sure this value matches the DNS record you created
          	server_name gitea.yourdomain.xyz;
        
          	root /var/www/html;
        
          	location / {
          		# Proxy all requests to Gitea running on port 3000
          		proxy_pass http://localhost:3000;
        
          		# Set headers
          		proxy_set_header HOST $host;
          		proxy_set_header X-Forwarded-Proto $scheme;
          		proxy_set_header X-Real-IP $remote_addr;
          		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          	}
          }
        
    • sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/gitea
      • This enables the configuration you just saved in nginx
    • sudo nginx -t
      • This command checks that your nginx configuration all looks good
    • sudo systemctl restart nginx
      • Necessary any time you make nginx configuration changes to apply them
    • sudo apt install certbot python3-certbot-nginx
      • Install certbot, which will allow you to serve your site over https (you want this)
    • sudo certbot --nginx -d gitea.yourdomain.xyz
  • Now visit your gitea page in a browser on any device: https://gitea.yourdomain.xyz
    • This will give you an initial setup page where you can specify some settings
  • Settings to change:
    • Database Type: SQLite3
    • Server Domain: should match the DNS record you created
    • Gitea Base Url: should match the DNS record you created WITH https:// at the beginning
    • Administrator Account Settings: this will be your admin account — use a good password
  • Hit install
    • May get a 502 after this — just wait a minute and it should resolve with a refresh
  • Welcome to Gitea

Optional

  • To manually edit settings (for example, set DISABLE_REGISTRATION = true):
    • sudo nano /var/snap/gitea/common/conf/app.ini
      • This will open the settings file, edit any settings you would like to change and then save
    • sudo systemctl restart snap.gitea.web
      • Restart gitea to apply changes
  • Styling Gitea:
    • Reference
    • Example:
      • sudo gitea embedded list **.tmpl
        • Get a list of available template files you can edit
      • sudo gitea embedded extract templates/home.tmpl
        • I want to edit the home page so I’m going to extract this one
      • sudo nano /var/snap/gitea/common/templates/home.tmpl
        • I delete some of the boilerplate on the home page and save my changes
      • sudo systemctl restart snap.gitea.web
        • Restart gitea to apply changes