blog-banner

How to Install GitLab 7.8 on Centos 5.5 with Apache and MySQL

  • Apache
  • CENTOS
  • Drupal Planet
  • GITLAB
  • MySql

Install GitLab CE on CentOS 7

GitLab is a web-based Git repository manager with wiki and issue tracking features. GitLab is written in ruby on rails.

Installing GitLab omnibus package won't be that difficult following the guide given here. But when it comes to installing GitLab on centos 5.5, it isn't that easy as there are no omnibus packages available for centos systems with versions less than 6.5. So let's look at the steps that need to be followed to make GitLab installation successful on centos 5.5:

1. Install the development tools necessary to compile applications from the source

yum -y groupinstall "Development Tools"
yum install perl-ExtUtils-MakeMaker

2. Install missing dependencies

yum install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib zlib-devel openssl-devel libyaml-devel 
readline readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel
ImageMagick libicu libicu-devel libffi-devel make bzip2 autoconf automake libtool bison iconv-devel redis

3. Install Git from Source

  • We need to make sure that the version of Git is 1.7.10 or higher. To check the Git version, use the following command:

git --version
  • You can skip step 4 when your git version is 1.7.10 or higher. If not, install it from the source. First, remove the installed version of Git:

yum -y remove git
  • Install the pre-requisite files for Git compilation:

yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
  • Then install Git from the source:

mkdir /tmp/git 
cd /tmp/git
curl --progress https://www.kernel.org/pub/software/scm/git/git-2.1.2.tar.gz | tar xz
cd git-2.1.3/
./configure
make
make install

4. Install Ruby 2.1.2

  • Remove the old Ruby 1.8 package if present. GitLab only supports the Ruby 2.0+ release series:

yum remove ruby
  • Remove any other Ruby build if it is still present:
cd 
make uninstall
  • Once the uninstallation is complete, then install ruby 2.1.2
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
  • To check the ruby version, use the following command:
ruby --version
  • The output should look like the below:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  • We need to install Bundler Gem as follows:
gem install bundler --no-ri --no-rdoc
5. We shall create a new user for Gitlab using the following command:
useradd --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
 
6. Install MySQL and create a new database for Gitlab
  • Install MySQL
yum install -y mysql-server mysql-devel
  • Login to MySQL (type the database root password):
mysql -u root -p
  • Create a user for GitLab (type the password you want to set in the command below):
CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
  • Create the GitLab production database:
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  • Grant the Gitlab necessary permissions
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
 
7. Configure Redis server
  • Make sure redis is started on boot:
chkconfig redis on
  • Configure redis to use sockets:
cp /etc/redis.conf /etc/redis.conf.orig
  • Disable Redis listening on TCP by setting 'port' to 0:
sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf
  • Enable Redis socket for default CentOS path:
echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
echo -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf
  • Create the directory which contains the socket
mkdir /var/run/redis
chown redis:redis /var/run/redis
chmod 755 /var/run/redis
  • Persist in the directory which contains the socket, if applicable
if [ -d /etc/tmpfiles.d ]; then
     echo 'd  /var/run/redis  0755  redis  redis  10d  -' | sudo tee -a /etc/tmpfiles.d/redis.conf
fi
  • Activate the changes to redis.conf:
/etc/init.d/redis restart
  • Add git to the redis group:
usermod -aG redis git
 
8. Install Gitlab and configure it
  • We'll install GitLab into the home directory of the user "git"
cd /home/git
  • Clone GitLab repository
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlab
  • Go to the GitLab installation folder and copy the example GitLab configuration file.
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
  • Edit GitLab config file according to your server, if you want to use a custom port then include it in the URL, else just give the domain alone
sudo -u git -H nano config/gitlab.yml
## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: http://git.yourdomain.com
    port: 8081 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
    https: false # Set to true if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
  • GitLab should have some permission, so make sure the following are done:
chown -R git log/
chown -R git tmp/
chmod -R u+rwX log/
chmod -R u+rwX tmp/
chmod -R u+rwX tmp/pids
chmod -R u+rwX tmp/sockets
chmod -R u+rwX public/uploads
  • Create a directory for satellites and set the permission properly
sudo -u git -H mkdir /home/git/gitlab-satellites
chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
  • Copy the example Unicorn config
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
  • Edit unicorn.rb file, set the number of workers to at least the number of cores
nproc
sudo -u git -H nano config/unicorn.rb
  • Copy the example Rack attack config
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
  • Configure Git global settings for git user, useful when editing via web and edit user.email according to what is set in gitlab.yml
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "example@example.com"
sudo -u git -H git config --global core.autocrlf input
  • Configure Redis connection settings
sudo -u git -H cp config/resque.yml.example config/resque.yml
  • Change the Redis socket path if you are not using the default CentOS configuration
sudo -u git -H nano config/resque.yml
sudo -u git cp config/database.yml.mysql config/database.yml
  • Update username/password in config/database.yml.
sudo -u git -H nano config/database.yml
  • Make config/database.yml readable to git only
sudo -u git -H chmod o-rwx config/database.yml
 
9. Install the gems
  • To install charlock_holmes gem, we require ICU package 4.2.1 or higher
cd /home/git/gitlab
curl -O http://download.icu-project.org/files/icu4c/4.2.1/icu4c-4_2_1-src.zip
tar -xvzf icu4c-4_2_1-src.zip
cd icu/source
./configure
make
sudo make install
gem install charlock_holmes --version '0.6.9.4'
  • To install all other gems, use the following command
sudo -u git -H bundle install --deployment --without development test postgres aws
 
10. Install Gitlab shell
  • GitLab Shell is SSH access and repository management software developed specially for GitLab.
  • Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
sudo -u git -H bundle exec rake gitlab:shell:install[v2.1.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
  • By default, the gitlab-shell config is generated from your main GitLab config.
sudo -u git -H nano /home/git/gitlab-shell/config.yml
  • Initialize Database and Activate Advanced Features
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  • Type yes to create the database. When do you see the Administrator account created?
Administrator account created:
login.........root
password......5iveL!fe
  • Install the Init script
cd /home/git/gitlab
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 2
  • Setup Log rotate
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  • Check if GitLab and its environment are configured correctly:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  • Compile the assets
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
  • Start the Gitlab instance and check the status using the following commands:
/etc/init.d/gitlab start
/etc/init.d/gitlab status
Gitlab service / Unicorn with PID 19988 is running.
Gitlab service / Sidekiq with PID 20031 is running.
 
11. If you don’t want to use the Nginx server (GitLab recommends Nginx), but use Apache, then follow the steps. 
  • These steps will be useful if you want to access GitLab from a specific port and sub-domain.
  • Create a new gitlab.conf file in your /etc/httpd/conf.d/ directory and add the following
   ServerName http://git.yourdomain.com
   DocumentRoot /home/git/gitlab/public
   ServerSignature Off
   ProxyRequests Off
   ProxyPreserveHost On
   ProxyPass         / http://127.0.0.1:8081/
   ProxyPassReverse  / http://127.0.0.1:8081/
   ErrorLog /var/log/httpd/error_log
   
       Order allow,deny   
       Allow from all
   
  • For the configuration to be recognized we need to restart Apache/httpd and Gitlab
/etc/init.d/httpd restart
/etc/init.d/gitlab restart