How To Start your own Git Server in less than 30 Minutes

It’s official GitHub sold us out, so what are the alternatives? You could switch to GitLab or BitBucket and wait till Microsoft or others buying them and get in an infinite loop, or you create your own Server! A small group of members started already an own Repo, sadly it was already too late because MS is already in discussion with GitHub since 2007, but the idea was really funny.

Microsoft_github

Requirements

  • Own a VPS, arubacloud seems the cheapest one (1 Euro/Month), but some process like creating and initializing your VPS sometimes takes over 30 mins. So, it might not be the fastest – but for 1 € what you expect?!
  • Choose your favorite GNU/Linux distribution, this guide explains it how you do this on Ubuntu 16.04 because of its simplicity.
  • A database server: I prefer Postgresql in this guide.
  • An own domain is optional.

Setup

  • Connect to your VPS over SSH and than type: sudo apt update && sudo apt upgrade. This ensures everything is really up2date.
  • Create a user, let’s call it ‘git’, sudo adduser git than sudo adduser git sudo.
  • Change to that user, sudo - git
  • After update and upgrade complete, install postgresql with the following command sudo apt-get install postgresql postgresql-contrib
  • After postgresql installation done, install nginx server with following command sudo apt-get install nginx
  • We are almost done, know lets download the binary for Gitea run the following command wget -O gitea https://dl.gitea.io/gitea/1.3.2/gitea-1.3.2-linux-amd64 and be sure that you are in /home/gitdirectory.
  • After download operation, give permission to it: chmod +x gitea
  • After this step, let us make necessity configuration in Nginx, sudo nano /etc/nginx/sites-available/gitserver and paste the following lines with editing (domain address or public IP address):

server {
listen 80;
server_name ;
location / {
proxy_pass :3000;
}
}

  • Make a link for a sites-enabled directory, to activate vhost file, run following command :sudo ln -s /etc/nginx/sites-available/gitserver /etc/nginx/sites-enabled/
  • Now we are almost done with nginx configuration, check if you have any syntax error with the following command sudo nginx -t.
  • Let’s create a service for Gitea, run following command: sudo nano /etc/systemd/system/gitea.service paste the following configuration:

[Unit]
Description=Gitea
After=syslog.target
After=network.target

[Service]
Type=simple
User=git
WorkingDirectory=/home/git/
ExecStart=/home/git/./gitea web
Restart=always

[Install]
WantedBy=multi-user.target

  • After saving the configuration you can restart nginx first than enable your gitea service by following command: sudo systemctl enable gitea.service and finally sudo systemctl start gitea.service.
  • Final configuration for postgresql: create postgres user and db for the system. For creating a new postgresql user, run sudo -u postgres psql -c "CREATE USER WITH PASSWORD '';"
  • Now run the following command: sudo -i -u postgres
  • Create a db createdb -O
  • exit

That’s all with PG, don’t forget your: <yourpostgresusername> <yourdbname> <yourpass>

Create Secure Connection With Let’s Encrypt

  • Run the following command : sudo add-apt-repository ppa:certbot/certbot
  • Update again : sudo apt-get update
  • Install cert-bot: sudo apt-get install python-certbot-nginx
  • Create a certificate: sudo certbot --nginx -d
  • Accept answers, than at the end it will ask for:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

In this case, we generally select 2. But it is totally your choice.

Gitea Setup

  • Now go to your domain or your_ip:3000 over a web browser. It will redirect you to your git server installation page, select Postgresql as Database Type in Database Settings, enter necessity information: <yourpostgresusername> <yourdbname> <yourpass>. Don’t forget to change Application URL in General Application Settings, set it to your domain or your_ip:3000.
  • And create admin user if you wish, you can also change server and services settings according to your necessity. After all configuration finish, press Install Gitea Button, you will probably see a 404 page. Go to your root domain, that’s it. You have an SSL certified, fast and cheap git server which runs like a charm.

You can make changes to your own configuration like this:

Open app.ini file:
sudo nano /home/git/custom/conf/app.ini

After you are done with changes:

sudo systemctl restart gitea.service

Your git service has an API! Checkout <yourip:3000_or_yourdomain>/api/swagger

Another little tip is to use migrater.py to migrate your project to your new git server!

GitHub Alternatives

There some discussions ongoing about what are the alternatives:

If you one of the alternatives or create your own Git Server with my example, it’s up to you but you got several options now.

Another option would be to encrypt your git.

Closing Words

Creating your own Server doesn’t cost much money and can be done in under 30 minutes, if you already have done similar setup it’s a work which can even be done in 10 minutes without any trouble.

We get now some good alternatives and my little guide can be used if you really work daily with Git and your not want to relay on the big provider.

Happy git’n!

Advertisements

Comments are closed.

Blog at WordPress.com.

Up ↑

%d bloggers like this: