vagrantにredmineをインストール


redmineをvagrantにインストールする機会があったのでメモ。

epelの追加

```Bat
sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
```

必要なソフトのインストール

```Bat
sudo yum groupinstall "Development Tools"
sudo yum -y install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel mysql-server mysql-devel httpd httpd-devel ImageMagick ImageMagick-devel ipa-pgothic-fonts git
```

rbenvのインストール

```Bat
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
exec $SHELL
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
```

ruby、railsのインストール

```Bat
rbenv install 2.0.0-p481
rbenv rehash
rbenv global 2.0.0-p481
gem install rails --no-ri --no-rdoc
gem install bundler
rbenv rehash
```

mysqlの設定

```Bat
sudo vim /etc/my.cnf
```

```Bat:my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

character-set-server=utf8 ← 追加

# 任意設定
innodb_file_per_table
query-cache-size=16M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]                       ← 追加
default-character-set=utf8    ← 追加
```
mysqlのリスタート

```bat
sudo service mysqld start
sudo chkconfig mysqld on
```
redmine用ユーザの作成

```Bat
mysql -u root -p
msyql> create user 'redmine'@'localhost' identified by 'redminepass';
mysql> grant all on *.* to 'redmine'@'localhost';
mysql> quit
```

redmineのダウンロード

```bat
wget http://www.redmine.org/releases/redmine-2.5.1.tar.gz
tar xvf redmine-2.5.1
```

データベースの設定

```bat
cd redmine-2.5.1/config
cp database.yml.sample database.yml
vim database.yml
```

```vim:database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine        ←書き換え
  password: "redminepass"  ←書き換え
  encoding: utf8

development:
  adapter: mysql2
  database: redmine_development
  host: localhost
  username: redmine        ←書き換え
  password: "redminepass"  ←書き換え
  encoding: utf8

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  database: redmine_test
  host: localhost
  username: redmine        ←書き換え
  password: "redminepass"  ←書き換え
  encoding: utf8
```

mailerの設定

```bat
cp configuration.yml.example configuration.yml
vim configuration.yml
```

```vim:conriguration.yml(修正前)
default:
  # Outgoing emails configuration (see examples above)
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: smtp.example.net
      port: 25
      domain: example.net
      authentication: :login
      user_name: "redmine@example.net"
      password: "redmine"
```

```vim:configuration.yml(修正後)
default:
  # Outgoing emails configuration (see examples above)
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "localhost"
      port: 25
      domain: example.net
```

redmineの仕上げ

```bat
bundle install --without development test
rake generate_secret_token
rake db:create RAILS_ENV=production
rake db:migrate RAILS_ENV=production
```

passengerのインストール

```bat
gem install passenger --no-ri --no-rdoc
# VM のメモリ量が少ないので passenger のコンパイルのために推奨
sudo dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap
sudo swapon /swap
rbenv exec passenger-install-apache2-module
```

最後のコマンドは対話系形式になっており、すべてEnterで大丈夫です。
最後に表示される下記をメモっておきます(環境によって違います)。

```vim
LoadModule passenger_module /home/vagratn/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so

<IfModule mod_passenger.c>
  PassengerRoot /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby.gems/2.0.0/gems/passenger-4.0.45
  PassengerDefaultRuby /home/vagrant/.rbenv/versions/2.0.0-p481/bin/ruby
</IfModule>
```

apacheの設定
passenger.confの作成

```bat
sudo vim /etc/httpd/conf.d/passenger.conf
```

```vim:passenger.conf
LoadModule passenger_module /home/vagratn/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so

<IfModule mod_passenger.c>
  PassengerRoot /home/vagrant/.rbenv/versions/2.0.0-p481/lib/ruby.gems/2.0.0/gems/passenger-4.0.45
  PassengerDefaultRuby /home/vagrant/.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
```

```bat
sudo vim /etc/httpd/conf/httpd.conf
```

```vim
# DocumentRoot "/var/www/html"
DocumentRoot "/var/lib/redmine/public"
```