Install Redmine 2.5.1, and GitLab 6.8 on CentOS 6.5 and Apache 2.2

# Install rbenv

## Items to install
- rbenv 0.4.0-129-g7e0e85b
- ruby-build 20141210
- ruby 1.9.3-p551
- ruby 2.1.5
- rbenv-rehash
- bundler

## Install dependencies

```bash
$ yum install --enablerepo=epel make gcc zlib-devel openssl-devel readline-devel ncurses-devel gdbm-devel db4-devel libffi-devel tk-devel libyaml-devel
```

## Install rbenv and ruby-build

```bash
$ su -
$ git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
$ mkdir /usr/local/rbenv/shims /usr/local/rbenv/versions
$ groupadd rbenv
$ chgrp -R rbenv /usr/local/rbenv
$ chmod -R g+rwxXs /usr/local/rbenv
$ git clone git://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build
$ cd /usr/local/rbenv/plugins/ruby-build
$ ./install.sh
$ cat >> /etc/profile.d/rbenv.sh << EOF
export RBENV_ROOT="/usr/local/rbenv"
export PATH="/usr/local/rbenv/bin:$PATH"
eval "$(rbenv init -)"

EOF
$ source /etc/profile.d/rbenv.sh
$ rbenv -v
rbenv 0.4.0-129-g7e0e85b
$ ruby-build --version
ruby-build 20141210
```

## Install Ruby

```bash
$ rbenv install --list
$ rbenv install 1.9.3-p551 && rbenv install 2.1.5
$ rbenv versions
* system (set by /usr/local/rbenv/version)
  1.9.3-p551
  2.1.5
```

## Install rbenv-rehash and bundler

```bash
$ rbenv global 1.9.3-p551
$ gem --version
1.8.23.2
$ gem update --system
$ gem --version
2.4.5
$ gem install rbenv-rehash --no-rdoc --no-ri
$ gem install bundler --no-rdoc --no-ri
$ gem install rails --no-rdoc --no-ri
$ rbenv rehash

$ rbenv global 2.1.5
$ gem --version
2.2.2
$ gem update --system
$ gem --version
2.4.5
$ gem install rbenv-rehash --no-rdoc --no-ri
$ gem install bundler --no-rdoc --no-ri
$ gem install rails --no-rdoc --no-ri
$ rbenv rehash

```

## Create a mysql database and user

```bash
$ mysql -u root -p
mysql> create database redmine default character set utf8;
mysql> grant all on redmine.* to redmine@localhost identified by '********';
mysql> flush privileges;
mysql> exit;
```
















# Install GitLab


## Items to install
- git 1.9.4
- gitlab 6.8
- gitlab-shell 1.9.8


## Install git

```bash
$ yum install perl-ExtUtils-MakeMaker
$ cd ~/download && wget https://www.kernel.org/pub/software/scm/git/git-1.9.4.tar.gz && tar zxvf git-1.9.4.tar.gz && cd git-1.9.4
$ ./configure --prefix=/usr/local && make prefix=/usr/local all && make prefix=/usr/local install
$ git version
git version 1.9.4
```

## Install modules

```bash
$ sudo gem install charlock_holmes --version '0.6.9'
```

## Create git user

```bash
$ useradd -c 'GitLab' -s /bin/bash git
$ su - git
$ cd /home/git
$ mkdir .ssh
$ touch .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys
$ chmod 700 .ssh
$ git config --global user.name  "GitLab"
$ git config --global user.email "gitlab@example.com"
```

## Install gitlab-shell

```bash
$ cd /home/git
$ git clone https://github.com/gitlabhq/gitlab-shell.git
$ cd gitlab-shell
$ git checkout v1.9.8
$ git checkout -b v1.9.8
$ cp /home/git/gitlab-shell/config.yml.example /home/git/gitlab-shell/config.yml
$ vi /home/git/gitlab-shell/config.yml
$ diff /home/git/gitlab-shell/config.yml{.example,}
5c5
< gitlab_url: "http://localhost/"
---
> gitlab_url: "https://git.example.com/"
12c12
<   self_signed_cert: false
---
>   self_signed_cert: true
$ ./bin/install
$ exit
```

## Install gitlab

```bash
$ su - git
$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
$ cd gitlab
$ git checkout 6-8-stable
$ cp config/gitlab.yml.example config/gitlab.yml
$ vi config/gitlab.yml
$ diff config/gitlab.yml{.example,}
18c18
<     host: localhost
---
>     host: git.example.com
38c38
<     email_from: gitlab@localhost
---
>     email_from: gitlab@example.com
41c41
<     support_email: support@localhost
---
>     support_email: gitlab@example.com
227c227
<     bin_path: /usr/bin/git
---
>     bin_path: /usr/local/bin/git
$ cp config/unicorn.rb.example config/unicorn.rb
$ mkdir /home/git/gitlab-satellites
$ chmod 750 /home/git/gitlab-satellites
```


## Install bundle modules

```bash
$ cd /home/git/gitlab
$ bundle install --deployment --without development test postgres
```

## Configure mysql database

```bash
$ mysql -u root -p
mysql> create user 'gitlab'@'localhost' identified by '*********';
mysql> create database if not exists `gitlabhq_production` default character set `utf8` collate `utf8_unicode_ci`;
mysql> grant all on `gitlabhq_production`.* to 'gitlab'@'localhost';
mysql> exit;
$ cd /home/git/gitlab
$ cp config/database.yml.mysql config/database.yml
$ vi config/database.yml
$ diff config/database.yml{.mysql,}
10,11c10,11
<   username: git
<   password: "secure password"
---
>   username: gitlab
>   password: "*********"
24,25c24,25
<   username: root
<   password: "secure password"
---
>   username: gitlab
>   password: "*********"
37,38c37,38
<   username: root
<   password:
---
>   username: gitlab
>   password: "*********"
```

## Initialize database

```bash
$ bundle exec rake gitlab:setup RAILS_ENV=production
```

## Create self certificates

```bash
$ cd /etc/pki/tls/certs/
$ sed -i 's/365/3650/g' Makefile
$ make example.com.crt
umask 77 ; \
  /usr/bin/openssl genrsa -aes128 2048 > example.com.key
Generating RSA private key, 2048 bit long modulus
.........+++
...................................+++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
umask 77 ; \
  /usr/bin/openssl req  -new -key example.com.key -x509 -days 3650 -out example.com.crt -set_serial 0
Enter pass phrase for example.com.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Kanagawa
Locality Name (eg, city) [Default City]:Yokohama
Organization Name (eg, company) [Default Company Ltd]:Example Company
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server hostname) []:*.example.com
Email Address []:admin@example.com

$ openssl rsa -in example.com.key -out example.com.key
```


## Install initScript

```bash
$ exit
$ cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
$ cp /home/git/gitlab/lib/support/init.d/gitlab.default.example /etc/default/gitlab
$ chmod +x /etc/init.d/gitlab
```

## Make gitlab start after httpd

```bash
$ vi /etc/init.d/gitlab
$ diff /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
6a7,8
> # chkconfig: - 86 15
>
$ chkconfig --add gitlab
$ chkconfig gitlab on
$ ls -l /etc/rc.d/rc3.d/ | grep "httpd\|gitlab"
lrwxrwxrwx  1 root root 15 Apr 21 11:57 S85httpd -> ../init.d/httpd
lrwxrwxrwx  1 root root 16 May 19 11:12 S86gitlab -> ../init.d/gitlab
```

## Configure logrotation

```bash
$ cp /home/git/gitlab/lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
```

## Build asset

```bash
$ cd /home/git/gitlab
$ bundle exec rake assets:precompile RAILS_ENV=production
```

## Check status

```bash
$ cd /home/git/gitlab
$ bundle exec rake gitlab:check RAILS_ENV=production
```

## Configure Apache

```bash
$ wget -O /etc/httpd/conf.d/vhost_git.example.com.conf https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/web-server/apache/gitlab-ssl.conf
$ vi /etc/httpd/conf.d/vhost_git.example.com.conf

#This configuration has been tested on GitLab 6.0.0 and GitLab 6.0.1
#Note this config assumes unicorn is listening on default port 8080.
#Module dependencies
#  mod_rewrite
#  mod_ssl
#  mod_proxy
#  mod_proxy_http
#  mod_headers

# This section is only needed if you want to redirect http traffic to https.
# You can live without it but clients will have to type in https:// to reach gitlab.
<VirtualHost *:80>
  ServerName git.example.com
  ServerSignature Off

  RewriteEngine on
  RewriteCond %{HTTPS} !=on
  RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
</VirtualHost>

<VirtualHost *:443>
  SSLEngine on
  #strong encryption ciphers only
  #see ciphers(1) http://www.openssl.org/docs/apps/ciphers.html
  SSLCipherSuite SSLv3:TLSv1:+HIGH:!SSLv2:!MD5:!MEDIUM:!LOW:!EXP:!ADH:!eNULL:!aNULL
  SSLCertificateFile    /etc/pki/tls/certs/example.com.crt
  SSLCertificateKeyFile /etc/pki/tls/certs/example.com.key
  #SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt

  ServerName git.example.com
  ServerSignature Off

  ProxyPreserveHost On

  <Location />
    Order deny,allow
    Allow from all

    ProxyPassReverse http://127.0.0.1:8080
    ProxyPassReverse http://git.example.com/
  </Location>

  #apache equivalent of nginx try files
  # http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
  # http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
  RewriteEngine on
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]
  RequestHeader set X_FORWARDED_PROTO 'https'

  # needed for downloading attachments
  DocumentRoot /home/git/gitlab/public

  #Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
  ErrorDocument 404 /404.html
  ErrorDocument 422 /422.html
  ErrorDocument 500 /500.html
  ErrorDocument 503 /deploy.html

  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
  ErrorLog  /var/log/httpd/git.example.com-error.log
  CustomLog /var/log/httpd/git.example.com-forwarded.log common_forwarded
  CustomLog /var/log/httpd/git.example.com-access.log combined env=!dontlog
  CustomLog /var/log/httpd/git.example.com.log combined

</VirtualHost>

```















# Install Redmine

## Install Redmine 2.5.1 on Ruby 2.1.5

```bash
$ wget http://www.redmine.org/releases/redmine-2.5.1.tar.gz
$ tar zxf redmine-2.5.1.tar.gz
$ mv redmine-2.5.1 /var/lib/redmine
$ cat >> /var/lib/redmine/config/database.yml<< EOF
production:
  adapter: mysql2
  database: db_redmine
  host: localhost
  username: user_redmine
  password: ********
  encoding: utf8

EOF

$ cat >> /var/lib/redmine/config/configuration.yml<< EOF
production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "localhost"
      port: 25
      domain: 'example.com'

  rmagick_font_path: /usr/share/fonts/ipa-pgothic/ipagp.ttf

EOF

$ rbenv global 2.1.5
$ cd /var/lib/redmine/
$ bundle install --without development test
$ bundle exec rake generate_secret_token
$ RAILS_ENV=production bundle exec rake db:migrate
$ gem install passenger --no-rdoc --no-ri
$ passenger-install-apache2-module
$ cat >> /etc/httpd/conf.d/passenger.conf << EOF

LoadModule passenger_module /usr/local/rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /usr/local/rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/passenger-4.0.42
  PassengerDefaultRuby /usr/local/rbenv/versions/2.0.0-p481/bin/ruby
</IfModule>


Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"

PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerHighPerformance on
PassengerStatThrottleRate 10
PassengerSpawnMethod smart
RailsAppSpawnerIdleTime 86400
PassengerMaxPreloaderIdleTime 0

RackBaseURI /redmine

#<VirtualHost *:80>
#	ServerName redmine.example.com
#	# !!! Be sure to point DocumentRoot to 'public'!
#	DocumentRoot /var/lib/redmine/public
#	<Directory /var/lib/redmine/public>
#		# This relaxes Apache security settings.
#		AllowOverride all
#		# MultiViews must be turned off.
#		Options -MultiViews
#		# Uncomment this if you're on Apache >= 2.4:
#		#Require all granted
#	</Directory>
#</VirtualHost>

EOF

$ cat >> /etc/httpd/conf.d/vhost_redmine.example.com.conf << EOF
<VirtualHost *:80>
        ServerName redmine.example.com
        ServerSignature Off

        RewriteEngine on
        RewriteCond %{HTTPS} !=on
        RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
</VirtualHost>

<VirtualHost *:443>
        ServerName redmine.example.com
        ServerSignature Off

        SSLEngine on
        SSLCertificateFile    /etc/ssl/certs/example.com.crt
        SSLCertificateKeyFile /etc/ssl/certs/example.com.key

        DocumentRoot /var/lib/redmine/public

        <Directory /var/lib/redmine/public>
                AllowOverride all
                Options -MultiViews
                #Require all granted
        </Directory>

        <IfModule mod_passenger.c>
                PassengerUser www-data
                PassengerGroup apache
        </IfModule>

        LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
        ErrorLog  /var/log/httpd/redmine.example.com-error.log
        CustomLog /var/log/httpd/redmine.example.com-forwarded.log common_forwarded
        CustomLog /var/log/httpd/redmine.example.com-access.log combined env=!dontlog
        CustomLog /var/log/httpd/redmine.example.com.log combined
</VirtualHost>

EOF

$ ln -s /var/lib/redmine/public /var/www/html/redmine.example.com
$ chown -R www-data:apache /var/lib/redmine
$ service httpd restart
```



# Integrate GitLab with Redmine

## Join apache user (www-data) in git group

```bash
$ groups www-data
www-data : apache
$ usermod -a -G git www-data
$ groups www-data
www-data : apache git
```

## Make git home directory accessible

```bash
$ chmod g+rx /home/git/
```

## Create Redmine project and new repository

![redmine0.jpg](https://qiita-image-store.s3.amazonaws.com/0/22048/f712e2c2-37db-652b-2a3c-2d32de68740e.jpeg)


![redmine1.jpg](https://qiita-image-store.s3.amazonaws.com/0/22048/2edbe486-f253-be21-113e-f8444a8ad7c7.jpeg)