Tutorial

How to Setup GitLab on a DigitalOcean Droplet

Draft updated on Invalid Date
Default avatar

By Nicholas Cerminara

How to Setup GitLab on a DigitalOcean Droplet

This tutorial is out of date and no longer maintained.

Introduction

Okay – GitLab isn’t really your own self-hosted GitHub. I don’t believe GitLab or GitHub share any relationship besides both being Git Management Software, but it’s the best way I find to describe in laymen’s terms what GitLab is. GitLab is awesome. It’s featured packed, and it does nearly everything that GitHub does. Best of all, you get unlimited private repos with it (or technically as many as your server can handle).

I have some pretty good DevOps skills, but I’m not really a server guy. Until recently, I’ve never previously wanted to deal with the hassle of setting up my own Git server, and GitHub’s managed solution is really quite appealing. With GitHub, you have a reliable and easy solution that you never really have to worry about. It’s also very nicely integrated with a huge array of social features like forking and organizations amongst other collaboration tools. The only thing is it can get expensive real fast if you need more than a handful of private repositories.

DigitalOcean has recently made it very simple and straightforward to set up GitLab with minimal effort and fully supporting one-click restorable backups. They also even provide great resources and tutorials on it:

This post will be very similar to those articles, but I’ll be going through it step-by-step in more detail as well as some improvements and notes of my own. Feel free to read below or go straight to the DigitalOcean docs themselves.

Sign up with DigitalOcean

The first thing you’ll need to do is signup with DigitalOcean.

Setup Public SSH Keys

DigitalOcean automatically will provision your server with the public keys you upload to your account. This step isn’t really required, but it makes it easier and faster to access your new server environment.

Create Your Droplet

If you don’t know much about servers - don’t worry. DigitalOcean will make this very easy for us, and they’ll actually “automatically” do most of the work for us.

Select your Hostname

For this, use the domain (or subdomain) that you would like to use. For example, you could do gitlab.scotch.io.

Select the server size

The official recommendation for GitLab can be found here. In summary, your server should have:

  • 2 cores of CPU power
  • 2 GB RAM

However, I’ve found that GitLab still works well even if you don’t meet these requirements. If you select the smallest Droplet, GitLab will occasionally freeze or hang. This is usually fixed with a quick reboot of the server. I recommend the smallest Droplet you select is their $10/month plan. I have found no problems yet running this with a small team for both work and play.

Select a region

Select the region that you would like your server to be in. You should select a region that is closest to you to reduce latency.

Select an image

The next step is to select the GitLab application image provided by DigitalOcean. Selecting this basically means that GitLab will automatically be installed when the server is provisioned.

Select the SSH Key

Select the Public SSH Key you added from earlier. This will allow you to SSH into the server without needing a password. Selecting this also means that DigitalOcean won’t send you a root password when the Droplet is created.

Enable Backups

The last step is to enable backups. Even though Git is a distributed version control system, I still would enable this so that you can easily recover your Git repos if anything unexpected happens.

Configure the Server

Access the Droplet

Now that we have created our Droplet and before we do anything, lets SSH in and make some minor setting changes. To get the IP address of your Droplet, just navigate to your Droplets in the DigitalOcean backend. After you find it, open the terminal and connect with it via SSH (no password will be required since we are using public and private keys):

  1. ssh root@<IP Address>

Note: You can visit the IP address in your browser now to see GitLab is working. Don’t worry about that just yet, we’ll get to that soon enough.

Update the Hosts File

This helps remove warnings when rebooting GitLab. We’re going to add the hostname of your Droplet to the hosts file. To do this, open /etc/hosts with your favorite editor:

  1. vim /etc/hosts

Then, add your IP address, a tab, and the hostname on line 2 of that file:

  1. <IP Address> gitlab.scotch.io

Setup URLs and Emails

We’ll need to set some default settings and globals for GitLab. These are things like the base URL and default support email. Open the /home/git/gitlab-shell/config.yml and update the variable gitlab_url:

  1. vim /home/git/gitlab-shell/config.yml

After that, we’ll need to update one last file. Open up /home/git/gitlab/config/gitlab.yml in your editor:

  1. vim /home/git/gitlab/config/gitlab.yml

You can go through this file and make adjustments to customize your installation. Most of these are just default settings. For the most part, you should leave it as is, but you’ll need to change host under GitLab settings to your domain name.

host: gitlab.scotch.io

Then, you need to set the default From and Admin emails:

email_from: yo-its-me-gitlab@gitlab.scotch.io
support_email: nick@scotch.io

Reboot GitLab

To finalize everything, reboot GitLab with the following command:

service gitlab restart

Setup DNS

Point the A Record

The final step is to now point the A record of either the domain or subdomain to your DigitalOcean IP address. I use CloudFlare to manage my domains, but your setup should look very similar to the below screenshot:

Access Your New Git Server!

If everything worked out correctly and DNS propagated, you can now visit the URL in your browser to access your new git server!

You also can now SSH into your Droplet with the following command:

  1. ssh root@gitlab.scotch.io

Default Login

Now that you have successfully navigated to your URL, you’ll need to log in. The default login for this image is:

Username: admin@local.host
Password: <PASSWORD>

You probably noticed this already when you were SSH-ing into the server. This appears in the welcome message.

After you log in, you’ll be prompt to change the password, then you’ll need to log in again with the same email and the new password. Once you have logged in successfully, you’ll need to change the default Admin email to your email address. To do this, navigate to the Admin Panel located here:

/admin/users/root/edit

Next, we’ll need to update the default username (which is currently root). To do this, navigate to:

/profile/account

After you make that change, you are all set on configuring the server!

Next Steps

GitLab has a whole bunch of cool features. I won’t go over everything in detail because a lot of it is self-explanatory, but some of the things you should consider playing around with once logged in are:

  • Adding Public Keys
  • Creating Groups and Teams
  • Customizing Themes
  • Your own GitLab API
  • Webhooks

Debugging, Troubleshooting, and Backups

If GitLab ever hangs or freezes on you, you can try rebooting it with:

  1. service gitlab restart

If that doesn’t work, you can reboot your entire Droplet through the command line with:

  1. shutdown -h now

or

  1. sudo reboot

When you do a power cycle from the command line like this, DigitalOcean will take a snapshot of your Server in case you need to safely restore. If that doesn’t work, you can just login to your DigitalOcean account and reboot the Droplet through their backend.

If you ever need to restore from a backup, all you have to do is log into the backend of DigitalOcean, select your Droplet, and click Restore from Backup.

Conclusion

That’s all there is to get your own little private Git server. GitLab is an amazing tool, and the awesome guys over at DigitalOcean have made it really straightforward to set one up with backups, hardened security, “unlimied” privated repos, and more.

I’m a huge fan of DigitalOcean and their services, and I highly recommend that you use them. GitHub is really worth every penny, but if you’re in need of a ton of private repos on a tight budget, GitLab might be the best solution for you.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Nicholas Cerminara

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel