Skip to content →

Installation & Configuration of GitBucket – A self-hosted alternative to GitHub

In the previous tutorial titled How to Install GitLab CE to have your own CI (Continuous Integration) with Source Control on Debian 10 we went over the advantages of GitLab. However GitLab is notoriously fickle in a production environment; updating it can easily break your entire workflow and it isn’t the most reliable solution for someone who just needs GUI-assisted commit tracking.

In comes GitBucket a fully self-contained GitHub clone (written in Scala) that you can host yourself and that runs off of the JVM.

Step 0:

First you will have to ensure that your machine has at-least Java8 installed.

In this case we will use the OpenJDK version (because we like open source and development) but note that you can also use the OpenJRE as well as the Oracle Java.

sudo apt-get install default-jdk

Check that your Java version is higher than 8

java --version 

In our case we have 11.0.9 which is good

openjdk 11.0.9 2020-10-20 OpenJDK Runtime Environment (build 11.0.9+11-post-Debian-1deb10u1) OpenJDK 64-Bit Server VM (build 11.0.9+11-post-Debian-1deb10u1, mixed mode, sharing)

Step 1:

Now lets download the latest gitbucket.war file from the releases page

In our case it is version 4.34

wget https://github.com/gitbucket/gitbucket/releases/download/4.36.2/gitbucket.war

And give it a test run using the terminal

java -jar gitbucket.war

Now it should show up when you go to yourwebsite.com:8080

Step 2:

Lets enable SSL via proxing from your main site

If you don’t know how to enable SSL in OpenLiteSpeed refer to my previous tutorial titled Installation and Configuration of OpenLiteSpeed with PHP, MariaDB, LetsEncrypt SSL, PHPMyAdmin, and NinjaFirewall on Debian 10 Buster

Create a new VHOST with whatever parameters you want

Now you’ll want to go to External App->+ sign to add an external app, choose type Web Server

Fill in the details

Now add a new context of type proxy by going to Context->+

Now go to SSL and fill in the SSL parameters from your main domain

Enable Rewrite to HTTPs

Create an A record in your nameserver configuration (in your nameserver’s management interface – typically your domain provider) to point the gitbucket.yourwebsite.com subdomain to your server’s IP address

Add it in both HTTP and HTTPs Listeners for your created VHOST

Save all changes and Do a graceful restart

Now you should be able to visit your subdomain gitbucket.yourwebsite.com and it should automatically redirect to the HTTPS link (this is vital since the connection needs to be secure for logins)

Step 3:

Now that its running we need to make it into a service so that it starts automatically on reboots

First lets move it to somewhere that makes sense for an executable

cd ~
mv gitbucket.war /usr/bin/gitbucket.war
sudo nano /etc/systemd/system/gitbucket.service

Paste the following contents and save

Description=GitBucket Server Service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/java -jar /usr/bin/gitbucket.war
[Install]
WantedBy=multi-user.target

Now you’ll want to run the following commands to update, start and enable it to run at boot

sudo systemctl daemon-reload
sudo systemctl start gitbucket
sudo systemctl enable gitbucket

Now it should survive between reboots

You’re done 😉

Published in Uncategorized

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *