How to install Gitlab, Ruby and Nginx on a Debian 7 (Wheezy) VPS

GitLab is a fast, secure and stable solution to manage your projects. It is a self hosted Git management software based on Ruby on Rails and has a free and open-source license.

GitLab is one of the most installed git management applications in the world. With GitLab you can create projects and repositories, manage access and do code review.

In the following article we are going to show you how you can deploy GitLab on one of our Debian VPS hosting plans.

Before proceeding any further with the installation, fire up a screen session by running:

screen -U -S gitlab-install

and then make sure your Debian Wheezy server is fully up-to-date by executing the following commands:

apt-get update
apt-get upgrade

Next, proceed with installing some required packages. Do this by executing:

apt-get install sudo vim dialog 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 python-docutils

Then, set-up vim as your default editor by:

update-alternatives --set editor /usr/bin/vim.basic

once that’s completed, next thing to do is to verify you have the correct python version on your Debian Wheezy VPS. The Python version has to be greater than 2.5 and lower than 3.0+

apt-get install -y python
python --version
Python 2.7.3

now check if you can access python shell via ‘python2’:

test ! -e /usr/bin/python2 && ln -s /usr/bin/python /usr/bin/python2
python2 --version
Python 2.7.3

if everything is ok so far, then we are ready to compile and install ruby from source, so proceed by running the following commands:

mkdir -p /opt/ruby && cd /opt/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
make install

once ruby is compiled and installed on the system, install the bundler ruby gem with the following command:

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

Next, set-up ‘git’ system user and gitlab-shell for GitLab

adduser --disabled-login --gecos 'GitLab' git
cd /home/git
sudo -u git -H git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
sudo -u git -H git checkout v1.7.1
sudo -u git -H cp config.yml.example config.yml
sudo -u git -H vim config.yml

make sure you replace gitlab_url with your desired URL

sudo -u git -H ./bin/install

The next step is to set-up your MySQL database server:

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

enter your desired MySQL ‘root’ password when prompted

mysql -u root -p
mysql> GRANT ALL ON `gitlabDB`.* TO 'gitlab'@'localhost' identified by '<YOUR_DB_PASS>';
mysql> \q

Once you created the database that will be used by the GitLab application, proceed with the installation of GitLab:

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

cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
sudo -u git -H vim config/gitlab.yml

change the host variable to your desired URL

next, set-up some necessary directory permissions:

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

and proceed with configuring the unicorn HTTP server:

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H vim config/unicorn.rb

make sure you tune unicorn to suit your needs. be careful how much resources you allocate and actually have. you can always start with something like worker_processes 1 and timeout 120

finally, perform the following git configuration:

sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@<YOUR_URL>"
sudo -u git -H git config --global core.autocrlf input

next thing to do is to set-up the database connection. Do this by executing the following commands:

sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H vim config/database.yml

make sure you change the following under the production section:

database: gitlabDB
username: gitlab
password: "<YOUR_DB_PASS>"
sudo -u git -H chmod o-rwx config/database.yml

install some other required ruby gems:

cd /home/git/gitlab
gem install charlock_holmes --version ''
sudo -u git -H bundle install --deployment --without development test postgres aws

initialize the database

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

make sure to type ‘yes’ when prompted

proceed with setting-up gitlab’s init script

cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
update-rc.d gitlab defaults 21

then check gitlab application status and start the appliaction by running:

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
service gitlab start

The final step is to install and set-up Nginx in front of GitLab:

apt-get install nginx
rm -f /etc/nginx/sites-enabled/default
cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
vim /etc/nginx/sites-available/gitlab

make sure to change server_name YOUR_SERVER_FQDN to server_name <YOUR_URL>

finally, restart nginx by executing:

service nginx restart


navigate to http://<YOUR_URL> and login using:


PS If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Categories: Tutorials

View Comments

Leave a Comment