How To Run Your Own Git Server With GitlabHQ On Debian 7 (Wheezy)

Version 1.0
Author: Srijan Kishore

This document describes how to install and configure Git and GitHub. These are great tools to manage and administer a whole host of Git repositories and the associated permissions. So, these remain true blessings for users writing open source software, however, when writing a closed source software may not be comfortable in trusting the code to a third party server. To gain the much-needed flexibility and control on stuff like Github/BitBucket without hosting the git repositories on servers that lie external to the control of users, GitLab remains a Godsend!

GitLab is a wonder tool that offers a simple and user-friendly yet potent web-based interface to the Git repositories on your server, viz., GitHub. Users are free to host it on their own cloud server, control access in a custom-built manner, and the only factor limiting the repo size is the inbuilt storage space of the server.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

This tutorial is based on Debian 7 server, so you should set up a basic Debian 7 server installation before you continue with this tutorial. The system should have a static IP address. I use 192.168.0.100 as my IP address in this tutorial and server1.example.com as the hostname. All the requisite software must be installed to make GitLab work. Hence, those using an existing VPS (droplet)/an altogether different Linux distro may face disruptions, expressly with incompatible Python and Ruby versions. Hence, it is imperative to have Ruby 2.0 and Python 2.7 installed at the outset. 

2 Installation of Ruby 2.0 or above, Python 2.7 and Bundler Gem

We will first install the pre-configurations before configurations of the Git Hub.The process for installation of required packages has been explained below. 

apt-get update
apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl git-core openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev

Note: Users must ensure that Ruby 1.8 is not installed on their system, though chances are remote that it would be so on a default Debian 7.6

You can check your Python version as follows(in my case it is Python 2.7.3):

python --version

[email protected]:~# python --version
Python 2.7.3
[email protected]:~#

This can be done as shown below, installing Ruby 2.1.2, Ruby can be installed as follows:

mkdir /tmp/ruby && cd /tmp/ruby
wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
tar zxvf ruby-2.1.2.tar.gz
cd ruby-2.1.2
./configure
make
make install

Further we will check the ruby version as:

ruby -v

[email protected]:/tmp/ruby/ruby-2.1.2# ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
[email protected]:/tmp/ruby/ruby-2.1.2#

Next we will install the Bundler Gem as follows:

gem install bundler --no-ri --no-rdoc

[email protected]:/tmp/ruby/ruby-2.1.2# gem install bundler --no-ri --no-rdoc
Fetching: bundler-1.6.5.gem (100%)
Successfully installed bundler-1.6.5
1 gem installed
[email protected]:/tmp/ruby/ruby-2.1.2#

Now we will create  a user=git user for Gitlab to be used in further configurations,as follows:

adduser --disabled-login --gecos 'GitLab' git

3 Installation of the GitLab Shell

 We will download the GitLab shell using the following command :

cd /home/git
apt-get install sudo
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
sudo -u git -H git checkout v1.7.0
sudo -u git -H cp config.yml.example config.yml

Further we will make a backup of original file config.yml.example and copy it into config.yml. Edit the file as follows:

vi config.yml

Now we need to change the value from gitlab_url: "http://localhost/" to git value as shown:

# GitLab user. git by default
user: git

# Url to gitlab instance. Used for api calls. Should end with a slash.
#gitlab_url: "http://localhost/"
gitlab_url:     "http://server1.example.com"

[....]

Now we will run the GitLab shell installed as follows:

sudo -u git -H ./bin/install

It will have output like this:

[email protected]:/home/git/gitlab-shell# sudo -u git -H ./bin/install
mkdir -p /home/git/repositories: true
mkdir -p /home/git/.ssh: true
chmod 700 /home/git/.ssh: true
touch /home/git/.ssh/authorized_keys: true
chmod 600 /home/git/.ssh/authorized_keys: true
chmod -R ug+rwX,o-rwx /home/git/repositories: true
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true
[email protected]:/home/git/gitlab-shell#

4 MySQL installation for GitLab

Now, we will set up the GitLab to use a MySQL to be used in backend. The first step is to install MySQL with the command given below. During the installation process, it will prompt you for setting up a MySQL root password, which you may set as per personal preference, however you must make a note of the same for use in the subsequent steps.

apt-get install mysql-server mysql-client libmysqlclient-dev

New password for the MariaDB "root" user: <--mysqlpassword
Repeat password for the MariaDB "root" user: <--mysqlpassword

Gitlab database creation:

mysql -u root -p

In MySQL prompt use database=gitlabdb user=gitlabuser and password=gitlabuserpassword:

CREATE DATABASE gitlabdb DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON gitlabdb.* TO 'gitlabuser'@'localhost' IDENTIFIED BY 'gitlabuserpassword';
flush privileges;
quit

Now we wil proceed for the installation as follows:

cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd /home/git/gitlab
sudo -u git -H git checkout 6-0-stable
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

Just as with the GitLab shell set up, if you have a domain configured for the VPS, you must edit the config.yml to use that domain (as shown in the command given below):

sudo -u git -H vi config/gitlab.yml

[...]
# # GitLab settings # gitlab: # ## Web server settings # host: localhost # port: 80 # https: false gitlab: ## Web server settings host: server1.example.com port: 80 https: false
[...]

Here, you are also required to set a few Linux file permissions, configure the git user's Gitconfig, and set up some GitLabconfig and directories for the git user (as shown below):

cd /home/git/gitlab
chown -R git log/
chown -R git tmp/
chmod -R u+rwX  log/
chmod -R u+rwX tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo -u git -H mkdir tmp/pids/
sudo -u git -H mkdir tmp/sockets/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
sudo -u git -H mkdir public/uploads
chmod -R u+rwX  public/uploads
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "[email protected]"
sudo -u git -H git config --global core.autocrlf input
sudo -u git cp config/database.yml.mysql config/database.yml

Next, we need to tell GitLab to use the gitlab Mariadb user that you had set up earlier. For this, we will edit the file config/database.ymlfile (as shown below):

sudo -u git -H vi config/database.yml

[...]
#production: # adapter: mysql2 # encoding: utf8 # reconnect: false # database: gitlabhq_production # pool: 10 # username: root # password: "secure password" production: adapter: mysql2 encoding: utf8 reconnect: false database: gitlabdb pool: 10 username: gitlabuser password: "gitlabuserpassword"
[...]

Please put the values as you gave at the time of database creation, the above values may differ if you have used other values at the time of database creation. Change the file permissions as:

sudo -u git -H chmod o-rwx config/database.yml

Now, we can install a few more needed gems, and this may be a fairly long step (as shown below):

cd /home/git/gitlab
gem install charlock_holmes --version '0.6.9.4'

Download the package and install it:

wget https://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.1.1-omnibus-1_amd64.deb
apt-get install openssh-server
apt-get install postfix # Select 'Internet Site', using sendmail instead also works, exim has problems

Here it will ask for some user input, please select Internet Site, use system mail as server1.example.com  You can also use sendmail instead installing postfix. In this case exim don't work. Next install the git lab:

dpkg -i gitlab_7.1.1-omnibus-1_amd64.deb

Edit the configuration file to add our hostname i.e. hostname=server1.example.com:

vi /etc/gitlab/gitlab.rb


[....]
#external_url 'http://gitlab.example.com' external_url 'http://server1.example.com'

We will then reconfigure the start the GitLab as follows:

gitlab-ctl reconfigure

You can browse the login page at http://192.168.0.100/users/sign_on use the credentials as username=root and password=5iveL!fe


Change the original password:




This will be your default welcome page.


Share this page:

3 Comment(s)

Add comment

Comments

From: planet_fox

Works, but I have chnage the ngnix user

nginx.conf from www-data to git

The Error was 

[crit] 30312#0: *1 connect() to unix:/home/git/gitlab/tmp/sockets/gitlab.socket failed 

From: Andriana

Nice tutorial thank you.

Everithing goes well but, when I go to the frontpage with this url:

http://my.ip.adress/users/sign_on

It gaves me an error 404

What's wrong?

Thank you for your help.

PS: I have installed nginx last time because the server doesn't have an http interpreter. So I just install it with apt-get install nginx.

Thank you for your feedback.

From: Andriana

This is the real url:

I also tried: "http://my.ip.adress/users/sign_in" looking to the picture you put.

As you can see a "Page not found" is showed.

Thank you for your feedback!