Self hosted Git service with Gogs

I’ve been searching for a solution for private repositories that would not assume paying Github. It was not the money that represented an issue, but actually the security as I wanted it to be more internal and private, while Github was after all subject to a password reuse attack, because if they know it’s public they’ll try it.

So I ended up having to choose between Gogs and GitLab. I tried to install GitLab on the DO droplet, but because it only had 512MB of RAM it didn’t want to run as apparently the minimum memory requirement to run GitLab is 4GB.

I reset the droplet and gave Gogs a try. And because I was really impressed with it I’m gonna share with you a tutorial to set it up yourselves.

As you are probably already aware I use Debian for my builds/tests so this tutorial is for Debian 8 Jessie.

First and foremost you must have a VPS or whatever, running the minimum install of Debian 8 and a correct IP/hostname assigned to it.

Now once this is solved we can move onto installing GoGs from the packager.io repo and we start by adding the keys and repo:

wget -qO – https://deb.packager.io/key | apt-key add –
echo “deb https://deb.packager.io/gh/pkgr/gogs jessie pkgr” | tee /etc/apt/sources.list.d/gogs.list

Because the packager.io repo works with SSL support we must insure that apt supports SSL by installing the transport layer support:

apt-get install apt-transport-https

Okay, if you made it this far then you can install Gogs:

apt-get update
apt-get install gogs -y

Now that Gogs is installed we also need to install and setup MySQL and Nginx for both database and webserver support. I ripped this script from the official installation page and you should create a file named gogs.sh (or whatever you’d like) in which you copy/paste this script and then execute it:

APP_NAME=”gogs”
MYSQL_PASSWORD=“some password
HOSTNAME=“hostname.servername.com

# setup mysql server and database
debconf-set-selections <<CONFIG
mysql-server-5.5 mysql-server/root_password password ${MYSQL_PASSWORD}
mysql-server-5.5 mysql-server/root_password_again password ${MYSQL_PASSWORD}
CONFIG
apt-get install -y –force-yes mysql-server
mysql -uroot -p${MYSQL_PASSWORD} -e “create database if not exists ${APP_NAME};”

# setup nginx configuration
apt-get install -y nginx
cat > /etc/nginx/sites-available/default <<EOF
server {
listen 80;
server_name ${HOSTNAME};
location / {
proxy_pass http://localhost:3000;
}
}
EOF
service nginx restart

Make sure to change the MYSQL_PASSWORD value to a strong password to be used by the root MySQL user and the HOSTNAME value to the hostname of your server.

Further you can access the hostname or server IP in a browser tab and you should be prompted with the GoGs configuration page where you must fill in the setup values such as the MySQL password (same as used above if you did not create a separate user) along with admin account values and email values amongst other.

As soon as your install is complete you can login and enjoy your self hosted Git service.

The setup referenced above is only for HTTP support, while you can pass Gogs behind a Let’s Encrypt SSL certificate and I will make another tutorial shortly for that too.