GitLab Installation Tutorial Part 1

GitLab Installation Tutorial (Part1)

8 Apr 2016 11 min read

Well if you want on your own server a personal Git repository while using GitLab as repository platform, then you probably will face a problem of managing Gitlab, Nginx, and Plesk together.

So for successful GitLab installation follow our tutorial below.

Step 1 – Prerequisites

At the start, let’s make sure we have more or less fair condition.

There is a Linux CentOS v6.5 server with Plesk installed (was used version 12.5.30 as a ref., but the procedure has also been tested on version 12.0.18) and you are root on the server.

Primarily it’s necessary to install the latest version of Git (now 1.8.3.1) from PUIAS Computational repository:

$ wget -O /etc/yum.repos.d/PUIAS_6_computational.repo 
https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/install/centos/PUIAS_6_computational.repo
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias rpm 
--import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
sudo yum install git

or, for the instant version (now 2.6.1):

yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel cd /tmp
wget https://www.kernel.org/pub/software/scm/git/git-2.6.1.tar.gz tar xzvf git-2.6.1.tar.gz cd git-2.6.1 make 
prefix=/opt/git all make prefix=/opt/git install export PATH="/opt/git/bin:$PATH" ln -s /opt/git/bin/git /usr/bin/git

Check its installation with:

git --version

Since Git was created for Ruby v2.0+, the next step is to install the prerequisites, the OpenSSL extension and Ruby for current version (2.1.2):

yum install ruby

Or such command for the previous one:

yum install gcc zlib zlib-devel openssl-devel mkdir /tmp/ruby && cd /tmp/ruby curl --progress
ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz cd ruby-2.1.2/ext/openssl/ ruby extconf.rb make 
top_srcdir="../../" sudo make install top_srcdir="../../" cd ../../ ./configure --disable-install-rdoc make sudo make 
prefix=/usr/local install

Then use the gem command to install Bundler, a dependencies manager for Ruby:

gem install bundler --no-doc

Step 2 – GitLab

Now when all prerequisites done, it’s important to add the server for the GitLab CE (Community Edition) package with:

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

and at last set up the package with:

sudo yum install gitlab-ce

At the end of GitLab installation on your server , in the /var/opt/gitlab/ folder it  have to be adapted due to our needs.

In case you want your Git repository to be available at the address http://gitlab.wdscode.guru , then you have to edit the /etc/gitlab/gitlab.rb file and change the following values (above each of them we put a note with the meaning):

# External URL for the GitLab repository external_url 'http://gitlab.wdscode.guru' # Completely disable GitLab's Nginx, 
since we're going to use the Plesk one nginx['enable'] = false # Sets server SSH port 
gitlab_rails['gitlab_shell_ssh_port'] = 22

To use GitLab with SSL protocol it’s necessary to change external_url and add an option as below:

external_url 'http://gitlab.wdscode.guru' nginx['listen_https'] = false # to communicate with GitLab Nginx internally 
over HTTP, even if external_url is in HTTPS nginx['redirect_http_to_https'] = true # redirects all traffic to HTTPS

Specify HTTPS port as part of the external_url when it’s necessary to use it other than the default (443):

external_url 'http://gitlab.wdscode.guru:2443'

Since Apache cannot connect to a UNIX socket but instead need to be connected to a TCP Port, it’s important to verify your GitLab version and if it’s 8.0.x or 8.1.x, then you must also change the settings for the new gitlab-git-http-server:

gitlab_git_http_server['listen_network'] = "tcp" gitlab_git_http_server['listen_addr'] = "localhost:8181"

Don’t pay attention to configure above gitlab_git_http_server when using GitLab 8.2, and just put down:

gitlab_workhorse['listen_network'] = "tcp" gitlab_workhorse['listen_addr'] = "localhost:8181"

Supposing you need GitLab to send you emails, edit in the same file also SMTP server settings by typing in the server’s host (in our case mail.wdscode.guru), port (usually 25, if you do not use SSL/TLS) username and password to be used and authentication type (“plain” in our example):

gitlab_rails['gitlab_email_enabled'] = true gitlab_rails['gitlab_email_from'] = '[email protected] ' 
gitlab_rails['gitlab_email_display_name'] = 'wdscode Git Repository' gitlab_rails['gitlab_email_reply_to'] = 
'[email protected]' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "mail.wdscode.guru" 
gitlab_rails['smtp_port'] = 25 gitlab_rails['smtp_user_name'] = "[email protected]" gitlab_rails['smtp_password'] = 
"yourpassword" gitlab_rails['smtp_domain'] = "mail.wdscode.guru" gitlab_rails['smtp_authentication'] = "plain" 
gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = false 
gitlab_rails['smtp_openssl_verify_mode'] = 'none'

To move data folder in your virtual host’s one:

git_data_dir "/var/www/vhosts/wdscode.loc/git.wdscode.loc/git-data"

To move uploads folder as well:

gitlab_rails['uploads_directory'] = "/var/www/vhosts/wdscode.guru/git.wdscode.guru/uploads"

If you want to set backup folder and schedule:

gitlab_rails['backup_path'] = "/var/www/vhosts/wdscode.guru/git.wdscode.guru/backups" gitlab_rails['backup_keep_time'] =
 604800 # Limits backups lifetime to 7 days (604800 seconds)

Now reconfigure and start GitLab with previous settings using the command:

sudo gitlab-ctl reconfigure

Take notice that if right permissions are not set, those folders won’t be backupped by Plesk, so be careful when moving GitLab folders in the virtual host’s ones.

Because GitLab works with git user and group, and it enforces 700 as permissions on both data (/var/opt/gitlab/git-date/) and backup (/var/opt/gitlab/backups) folders, the fastest way to solve is to change folders permissions after each reconfiguration of GitLab (gitlab-ctl reconfigure), so that Plesk can back them up.

You can do it by following this command:

chmod a+x -R /var/www/vhosts/wdscode.guru/git.wdscode.guru/git-data chmod a+x -R 
/var/www/vhosts/wdscode.guru/git.wdscode.guru/uploads chmod a+x -R /var/www/vhosts/wdscode.guru/git.wdscode.guru/backups
ERP development final cta

Get a Custom Solution with Web Design Sun

At Web Design Sun, we specialize in building web applications for clients in every business and industry.  If you’re interested in custom applications for your business, contact us today.

Contact us today to get started

More From Blog

Mobile-First Design Principles

As web developers, we’ve been ready for the move to mobile-first design. Over the past years, we have shifted our design methodologies and development strategies to take the needs of mobile users into account.
20 May 2021 22 min read

WordPress Color Switch Feature

This useful WordPress Feature is rather easy to implement, and it can be interesting for those who time to time need to change some elements in a website design.
14 Feb 2018 8 min read

WordPress Numeric Pagination Without Plugin

In this post, we will show you how easy to add numeric pagination in your WordPress theme and style it nicely.
7 May 2017 8 min read