Set up your own GitLab instance on a Debian 7 (Wheezy) server

Content on this page is probably outdated and represents my personal knowledge, feelings and understading of things at that time.

After searching the web for a good (read: easy) way of installing GitLab on my Debian 7 (Wheezy) VPS I decided to go with the official instructions. But as usuall I had to make due with a bit of improvisation and therefore I’m writting down this modified quick’n’dirty version.

1. Dependencies

It's always good to update your machine prior doing anything major. root # apt-get update root # apt-get upgrade Note: I'm usually running my systems without sudo. This guide will presume you su-ed to root and are using sudo only to act as the git user. root # apt-get install sudo Now with the real dependencies: root # apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate Make sure you have installed Python version between 2.5 and 3.0 - by default wheezy comes with python 2.7 and that's good. Also it looks like python2 needs to be symlinked to python, which again by default should be a go. The check: user $ python --version user $ python2 --version We also need git 1.7.10 or higher, which again by default should be ok. To install: root # apt-get install git-core And to check the version: user $ git --version You will also need to have the mail sending installed and setup. This is way out of scope of this blog post. Next up is ruby. The official documentation suggest compiling it yourself, but there's no need, wheezy packs ruby (1.9.1 as of this writing) and again, this should be all ok. To install: root # apt-get install ruby ruby-dev To check: user $ ruby --version

System users

Add a user named "git" under which the whole sheebang will run: root # adduser --disabled-login --gecos 'GitLab' git root # sudo -u git -H git config --global user.name "GitLab" root # sudo -u git -H git config --global user.email "gitlab@localhost" root # sudo -u git -H git config --global core.autocrlf input

GitLab shell

As of this writing the latest gitlab shell is version 1.8.0 - check it and correct the branch part in the second command (-b v1.8.0): root # cd /home/git root # sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0 root # cd gitlab-shell root # sudo -u git -H cp config.yml.example config.yml Now you'll need to edit the configuration. Bare minimum is editing of "github_url" which has to be a dedicated domain/subdomain and cannot be a subdirectory. After that we'll install the GitLab shell. root # sudo -u git -H editor config.yml root # sudo -u git -H ./bin/install

Database

GitLab supports MySQL and PostgreSQL databases. The setup is nicely documented GitLab databases documentation

GitLab

As with GitLab Shell you'll need to check the latest stable branch of GitLab in the source and replace the 6-4-stable part in the second commend: root # cd /home/git root # sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-4-stable gitlab root # cd gitlab That'll check out the latest code and now you'll need to configure it. Again, the bare minimum configuration is the domain/subdomain (host directive near the top). root # cd /home/git/gitlab root # sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml root # sudo -u git -H editor config/gitlab.yml Next there's a bunch of checking/setting stuff that should already be done, but newertheless: root # chown -R git log/ root # chown -R git tmp/ root # chmod -R u+rwX log/ root # chmod -R u+rwX tmp/ root # sudo -u git -H mkdir /home/git/gitlab-satellites root # sudo -u git -H mkdir tmp/pids/ root # sudo -u git -H mkdir tmp/sockets/ root # chmod -R u+rwX tmp/pids/ root # chmod -R u+rwX tmp/sockets/ root # sudo -u git -H mkdir public/uploads root # sudo chmod -R u+rwX public/uploads There, a lot of groundwork done. Now we need to copy the example unicorn configuration and edit it (I didn't edit anything if I'm not mistaken, but ymmv): root # sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb root # sudo -u git -H editor config/unicorn.rb Next up is the Rack attack config: root # sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb root # sudo -u git -H editor config/initializers/rack_attack.rb Next up on the configuration is the database config. Ofcourse you need to configure the correct access credidentials. For MySQL: root # sudo -u git cp config/database.yml.mysql config/database.yml For PostgreSQL: root # sudo -u git cp config/database.yml.postgresql config/database.yml And edit config and make it read to git only afterwards: root # sudo -u git -H editor config/database.yml root # sudo -u git -H chmod o-rwx config/database.yml Next up are the gems, I suggest you go make yourself a coffie while this runs: For MySQL: root # cd /home/git/gitlab root # sudo -u git -H bundle install --deployment --without development test postgres aws For PostgreSQL: root # cd /home/git/gitlab root # sudo -u git -H bundle install --deployment --without development test mysql aws After that's done, we need to initialize the database and activate advanced features (oh my!). You'll need to follow the on-screen instructions and mark down the login. root # cd /home/git/gitlab root # sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production There we're almost done. Now we need to compile the assets: root # sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

Debian/Linux support stuff

Note: Most of the instructions that follow are for the straightforward installation as described above and need some tweaking if you have a special case. First we'll set the init script and set it so that GitLab will start on boot: root # ln -s /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab root # update-rc.d gitlab defaults 21 root # service gitlab start Next up is Logrotate: root # ln -s /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab Now you can check the application status (also handy later on): root # cd /home/git/gitlab root # sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production The final thing to do is to set up the nginx web server, we only skim this part, because there're a lot of good tutorial regarding this (you'll need to replace the hostname/subdomain to match what you used above). root # apt-get install nginx root # cp /home/git/gitlab/lib/support/nginx/gitlab /etc/nginx/sites-enabled/gitlab root # edit /etc/nginx/sites-enabled/gitlab root # service nginx reload

That's it!

Now you can open the domain/subdomain url and see for yourself. Special thanks to mmoll and newton on #gitlab@freenode irc for the help.

A lot more in depth documentation is available: