Skip to content

 

Looking for administering tools that would make your managing activities simpler ??? GitLab is one of the latest tools that can give you a sigh of a cool breeze.the question of but is raised up here. This works great in the open source software but issue rises in the closed source software, moreover, you may not really want to trust a third party server. So, what should be actually done to take the benefit of BitBucket without reaching to the third party server. The article on How to install GitLab makes it easy for you.

Go for GitLab. This provides simple yet a powerful web based interface to your Git repositories. You can host it on your own cloud server. You can have the complete control access over it. At the same time, it is important to make a note of the space available on your server while going ahead with GitLab.

The tutorial below will help you to set up a GitLab server over our Linux VPS Hosting Server.

Note: while following the tutorial, it is assumed that you are using a new Ubuntu 12.04 VPS. For GitLab to work, we will be installing all the required software. If you are going with an existing VPS or a different Linux, you may come across certain issues especially in the areas of incompatible Python and Ruby versions. Make it a necessity to have Ruby 2.0 and Python 2.7 version installed before you begin.

How to install GitLab

1.Here comes the first step that helps you to install required packages.

sudo apt-get update sudo 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

Do remember that you don't have Ruby 1.8 installed and on a either way on a default Ubuntu 12.04 VPS, it won't be installed

2. Install Ruby 2.0. This will take a while.

mkdir /tmp/ruby && cd /tmp/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 sudo make install

3. Follow the steps to check Ruby 2.0 is installed.

ruby --version

4. The output be should be visible as below

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

5. Next, we will be installing Bundler gem

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

6. We then create a Git user for GitLab use

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

Installing the GitLab Shell

1.Using the following commands, download the GitLab Shell

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.0 sudo -u git -H cp config.yml.example config.yml

This provides you with the copy of GitLab Shell 1.7.0 and the example config.ym1 is ready to go.

2. At the VPS if you have any domain name pointed, then you should take the time to edit config.ym1 to use this domain

nano config.yml

3. Some where near the top, there will be a line

gitlab_url: "http://localhost/"

4. Now Change the http://localhost/ portion so that it matches your domain name. So if your domain is www.ABC.com the line should look like this:

gitlab_url: "http://www.YOURDOMAIN.com/"

Now you can run the GitLab shell installer:

sudo -u git -H ./bin/install

Database Setup

Now we will set up GitLab to use a MySQL back end. The initial step is to install MySQL is with the below command. During this procedure, it will ask you to set the MySQL root password. You can set it to whatever you desire. Make note of it as you will need it for the next steps.

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

MySQL is now installed and the root password is set to the value you had chosen in the last step. Next is to create a MySQL user for GitLab to use. To start with this, we'll first save the necessary SQL queries to a temporary file. Type:

nano tempfile

Paste it in the following, changing the $password on the first line to a real password. Keep a note of this password as this will be your GitLab's database password.

CREATE USER 'gitlab'@'localhost' IDENTIFIED BY '$password'; CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

After following this Save the file and execute the following command (entering your MySQL root password from the first step at the prompt) to have MySQL execute your queries:

cat tempfile | mysql -u root -p

Now to check new MySQL user which was created successfully let's log in to mysql using the gitlabuser:

mysql -u gitlab -p

If you see some text followed by a:

mysql>

line then everything worked strongly. Go ahead and type:

exit;

Now, at the mysql> prompt to exit MySQL, and delete the tempfile file since it contains a password:

rm tempfile

At this point we have everything configured to install GitLab successfully, so let's proceed with the installation:

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

Now, what we did with the GitLab shell set up, if you have a domain configured for your VPS we need to edit the config.yml to use that domain.

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

Just near the top of the file you should see a text block that looks like the following:

gitlab: ## Web server settings
host: localhost
port: 80
https: false

Now change the host and do the entry to match your domain name. If your domain is www.ABC.com, then it should look like this:

gitlab: ## Web server settings
host: www.ABC.com
port: 80
https: false

Let us now set some linux file permissions, configure the git user's Git config. Also let us set up some GitLab config and directories for the git user:

cd /home/git/gitlab
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX log/
sudo 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/
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
sudo -u git -H mkdir public/uploads
sudo 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 "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input
sudo -u git cp config/database.yml.mysql config/database.yml

Next is to tell GitLab to use the gitlab MySQL user that we had set up earlier. To do this, edit the config/database.yml file:

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

Next, somewhere near the top there will be a section called production: which will contain username and password entries. By default it would look like this:

production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 10
username: root
password: "secure password"

Next is to change the username and password entries so that it matches to the GitLab database user that we had set up earlier. So, if the password you used for your GitLab MySQL user was $password the edited file should look like the following:

production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_
production pool: 10
username: gitlab
password: "$password"

Later, save the file, and we'll secure it so that other users of the server can't see the password:

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

Next is to install a few more needed gems (this step may take some time):

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

Then run some final setup (type yes when it asks,if you want to continue)

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

After this is over,  it will print a lot of information onscreen and at the end will show Administrator account created and give you your administrator credentials. It will look something like as given below:

Administrator account created:
[email protected]
password......5iveL!fe

Set up GitLab to start up whenever your server boots:

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

Once that is done run the following to make sure everything is working:

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

If you do not get any error messages and the data output by the command looks right then your GitLab install is working. Now it is almost finished! Start up GitLab with this command:

sudo service gitlab start

SetUp NGINX

Generally, GitLab works with the nginx web server by default. If you already have your own web server such as Apache set up then these steps don't apply. If you don't have follow these directions to install and configure nginx to work with GitLab:

sudo apt-get -y install nginx
cd /home/git/gitlab
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

Edit /etc/nginx/sites-available/gitlab to use your domain name:

sudo nano /etc/nginx/sites-available/gitlab

A bit of ways from the top of the file you will see an entry server_name which is set toYOUR_SERVER_FQDN. As in the previous steps, replace the YOUR_SERVER_FQDN with your domain name. The original file looks like this:

server { listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea server_name YOUR_SERVER_FQDN; #

If your domain is www.AbC.com then you should change it to look like this:

server { listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea server_name www.ABC.com; #

And restart nginx:

sudo service nginx restart

Finally you're done. Next connect to GitLab via your web browser using the Admin login and password from above (default user: [email protected], pass: 5iveL!fe) and enjoy GitLab.

Well, if you are using a 512MB VPS then due to GitLab's memory requirements it's quite likely you will come across 502 Bad Gateway an error. If that's the case, go on reading

Troubleshooting

502 Bad Gateway Error

GitLab has high memory requirements, so on 512MB VPSs it often gives an error on the first sign in. This is because GitLab uses a lot of memory on the very first login. Since the Ubuntu 12.04 VPS has no swap space when the memory is exceeded, parts of GitLab get terminated by itself. Needless to say, GitLab does not run well when parts of it are being unexpectedly terminated.

One of the easiest solutions is just to distribute more memory to your VPS, at least for the first sign in. If you don't want to do that, another option is to increase swap space. The quick fix is to run the following:

Your swapfile is now running and active, but to set it so that it's activated on each boot we need to edit/etc/fstab:

sudo nano /etc/fstab
Paste the following onto the bottom of the file:
/swapfile   none   swap   sw   0   0

Now restart your VPS:

sudo restart

Now, wait a minute VPS to reboot, and then try GitLab again. If it doesn't work the first time, refresh the Bad Gateway page a couple of times, and you should soon see the GitLab login page. So, its done!!!! By using the tutorial of how to install GitLab, the operations to be carried becomes easy.

WeCreativez WhatsApp Support
Our customer sales team is here to answer your questions. Ask us anything!
👋 Hi, how can I help?