X
    Categories: Tutorials

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
./configure
make
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> CREATE DATABASE IF NOT EXISTS `gitlabDB` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
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 '0.6.9.4'
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:

login………admin@local.host
password……5iveL!fe

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.

View Comments

  • Wow, excelent tutorial, thank you! Without this post I wouldn't do that, with it it was just copy-paste (I'v only used lighttpd instead of Ngix), thank you very much!

  • Hello, I installed gitlab first as my server.com/gitlab and now I would like to change and use subdomains gitlab.myserver.com I change in the four configuration files the /gitlab and comment the lines (in application.rb unicorn.rb gitlab.yml and config.yml in gitlab-shell) I rebuild the assets using bundle exec rake assets:clean RAILS_ENV=production bundle exec rake assets:precompile RAILS_ENV=production everything went good. I updated my gitlab file in nginx to have as server name gitlab.myserver.com When I go on it, I have git lab showing but some icons are not showing only few squares. Any Ideas of what can I do ? I can t find any solution on the web. I think I m gonna try setup everything AGAIN :)

    • Change your hostname/domain in the following files (If you already haven't done so) /home/git/gitlab/config/gitlab.yml /home/git/gitlab-shell/config.yml If that doesn't help, you can use Firebug or Chrome Developer Tools to inspect your page elements.

      • Change your hostname/domain in the following files (If you already haven't done so) /home/git/gitlab/config/gitlab.yml /home/git/gitlab-shell/config.yml If that doesn't help, you can use Firebug or Chrome Developer Tools to inspect your page elements.

    • yes you can, but you would have to configure the set-up to use apache instead of nginx. we might cover this set-up in the near future, though.

      • yes you can, but you would have to configure the set-up to use apache instead of nginx. we might cover this set-up in the near future, though.

  • If you have this "bundler command not found", you have to type "gem environment" and find your "EXECUTABLE DIRECTORY" and add to the PATH by "export PATH=$PATH:"

  • Hi, I would like to say THANKYOU too for this tutorial, it was very helpful for me. BUT an error occured at the step: "sudo -u git -H bundle install --deployment --without development test postgres aws", " OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server hello A: wrong version number" Which i solved by running the command : gem update --system Otherwise, all goes perfect.

  • Hello, I would like to just say THANK YOU. This one just works. One thing I made, I changed the gitlab version from: sudo -u git -H git checkout 6-0-stable to sudo -u git -H git checkout 6-2-stable Other things just copy/paste... already using the gitlab on my VM :)))