Redmine 3.4 を CentOS 7.4 にインストールする

## Redmine 3.4
CentOS 7.4.1708 に Redmine 3.4.2 をなるべくパッケージでインストールする手順です。
[前回](https://qiita.com/bezeklik/items/483b61c637c805f2945f)との大きな違いは Ruby が 2.3 から 2.4 に、Passenger も 4 から 5 に、GCC を 4 から
 6 にバージョン変更しているところになります。
~~現時点では /issue　を参照すると 500 エラーが出る致命的な状態で要調査。プラグインの影響か。~~
→ redmine_already_read が原因だったようです。

## インストール
### 検証環境
* VirtualBox 5.1.28 (homebrew-cask)
* CentOS 7.4.1708 (minimal)

    * RHSCL 2.4 (centos-sclo-rh)
    * Ruby 2.4.0p0 (centos-sclo-rh)
    * MySQL 5.7.19 (mysql57-community)
    * Apache 2.4.6 (updates)
    * Passenger 5.1.8 (passenger)
    * Git 2.9.3 (centos-sclo-rh)
    * GCC 6.3.1 (centos-sclo-rh)
    * Redmine 3.4.2 (GitHub)

### アップデート
```bash
yum clean all && yum -y update && reboot
```

### Yum-axelget
```bash
yum -y install epel-release && yum -y update && yum -y install yum-axelget
```

### RHSCL (Red Hat Software Collections) リポジトリ
```bash
yum -y install centos-release-scl-rh
```

### Ruby / Bundler
```bash
yum -y install rh-ruby24{,-{ruby-devel,rubygem-bundler}} && \
source scl_source enable rh-ruby24 && \
echo -e '#!/bin/bash\nsource scl_source enable rh-ruby24' > /etc/profile.d/rh-ruby24.sh && \
ln -s /opt/rh/rh-ruby24/root/usr/lib64/libruby.so.2.4 /usr/lib64/
```

### MySQL
```bash
yum -y install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm && yum -y install mysql-community-server && \
echo -e '\ncharacter-set-server = utf8mb4' >> /etc/my.cnf && \
systemctl start mysqld && systemctl enable $_ && \
grep "temporary password" /var/log/mysqld.log | awk '{print $11}' && \
mysql_secure_installation --use-default
```

#### データベースと DB ユーザーの作成
```bash
cat << "_EOQ_" | mysql -u root -p
CREATE DATABASE `redmine` DEFAULT CHARACTER SET utf8mb4;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'P@ssw0rd';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
_EOQ_
```

### Apache / Passenger
```bash
yum -y install yum-utils && yum-config-manager --add-repo https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo && \
yum -y install httpd mod_passenger && \
rpm -e --nodeps ruby{,-{irb,libs},gem{s,-{bigdecimal,io-console,json,psych,rack,rake,rdoc}}} && \
systemctl start httpd && systemctl enable $_ && \
firewall-cmd --zone=public --add-service=http{,s} --permanent && firewall-cmd --reload
```

### Git
```bash
yum -y install rh-git29 && source scl_source enable $_ && \
echo -e '#!/bin/bash\nsource scl_source enable rh-git29' > /etc/profile.d/rh-git29.sh
ln -s /opt/rh/rh-git29/root/usr/bin/* /usr/local/bin/
```

### Devtoolset-6 (Red Hat Developer Toolset 6.0)
```bash
yum -y install devtoolset-6 && source scl_source enable $_ && \
echo -e '#!/bin/bash\nsource scl_source enable devtoolset-6' > /etc/profile.d/devtoolset-6.sh
```
必須ではないが、標準リポジトリでは GCC のバージョンが 4.8.5 と古いため。

### その他ライブラリ
```bash
yum -y install {mysql-community,libxml2,libxslt,ImageMagick}-devel ipa-pgothic-fonts
```

### Redmine
```bash
cd /var/www && git clone https://github.com/redmine/redmine.git && \
cd redmine && git checkout `git tag | tail -n 1` && \
bundle config build.nokogiri --local --use-system-libraries && \
cat << "_EOF_" > config/database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: root
  password: P@ssw0rd
  encoding: utf8
_EOF_
bundle install --jobs=8 --without development test && \
bundle exec rake generate_secret_token && \
bundle exec rake db:migrate RAILS_ENV=production && \
bundle exec rake redmine:load_default_data RAILS_ENV=production REDMINE_LANG=ja && \
chown -R apache. /var/www/redmine && \
chmod -R 755 files log tmp public/plugin_assets
```

### Apache の VirtualHost 設定
```bash
cat << _EOF_ > /etc/httpd/conf.d/redmine.conf
<VirtualHost *:80>
    ServerName example.com
    Header always unset "X-Powered-By"
    Header always unset "X-Runtime"
    PassengerRuby `which ruby`
    DocumentRoot /var/www/redmine/public
    <Directory /var/www/redmine/public>
        AllowOverride all
        Require all granted
        Options -MultiViews
    </Directory>
</VirtualHost>
_EOF_
systemctl restart httpd
setenforce 0 #TODO
```

### テーマ
```bash
git clone --depth 1 https://github.com/akabekobeko/redmine-theme-minimalflat2 /var/www/redmine/public/themes/minimalflat && cd $_ && rm * -fr && git checkout origin/master -- src && mv src/* . && rmdir -p src && cd - && \
git clone --depth 1 https://github.com/tsi/redmine-theme-flat /var/www/redmine/public/themes/flat && \
git clone --depth 1 https://github.com/hardpixel/minelab /var/www/redmine/public/themes/minelab && \
git clone --depth 1 https://github.com/lqez/redmine-theme-basecamp-with-icon /var/www/redmine/public/themes/basecamp-with-icon && \
git clone --depth 1 https://github.com/makotokw/redmine-theme-gitmike /var/www/redmine/public/themes/gitmike
```
### プラグイン
```bash
git clone --depth 1 https://github.com/syagawa/redmine_absolute_datetime /var/www/redmine/plugins/redmine_absolute_datetime && \
git clone --depth 1 https://github.com/haru/redmine_wiki_extensions /var/www/redmine/plugins/redmine_wiki_extensions && \
git clone --depth 1 https://github.com/AlphaNodes/redmine_tweaks /var/www/redmine/plugins/redmine_tweaks && \
git clone --depth 1 https://github.com/cdwertmann/line_numbers /var/www/redmine/plugins/line_numbers && \
git clone --depth 1 https://github.com/suer/redmine_japanese_help /var/www/redmine/plugins/redmine_japanese_help && \
git clone --depth 1 https://github.com/onozaty/redmine-view-customize /var/www/redmine/plugins/view_customize && \
git clone --depth 1 https://github.com/peclik/clipboard_image_paste /var/www/redmine/plugins/clipboard_image_paste && \
git clone --depth 1 https://github.com/akiko-pusu/redmine_issue_templates /var/www/redmine/plugins/redmine_issue_templates && \
git clone --depth 1 https://github.com/akiko-pusu/redmine_issue_badge /var/www/redmine/plugins/redmine_issue_badge && \
git clone --depth 1 https://github.com/akiko-pusu/redmine_banner /var/www/redmine/plugins/redmine_banner && \
git clone --depth 1 https://github.com/tleish/redmine_editor_preview_tab /var/www/redmine/plugins/redmine_editor_preview_tab && \
git clone --depth 1 https://github.com/stpl/redmine_issue_history /var/www/redmine/plugins/redmine_issue_history && \
git clone --depth 1 https://github.com/bdemirkir/sidebar_hide /var/www/redmine/plugins/sidebar_hide && \
git clone --depth 1 https://github.com/haru/redmine_theme_changer /var/www/redmine/plugins/redmine_theme_changer && \
cd /var/www/redmine && \
bundle install --jobs=8 --without development test && \
bundle exec rake redmine:plugins:migrate RAILS_ENV=production && \
systemctl restart httpd
```

## Redmine 関連記事
* [Redmineのtextile記法のテーブル - Qiita](https://qiita.com/bezeklik/items/e821a2816041f73ebb1f)
* [CentOS 7 に Redmine 3.3 をインストールする - Qiita](https://qiita.com/bezeklik/items/483b61c637c805f2945f)
* [Redmine 3.4 を CentOS 7.4 にインストールする - Qiita](https://qiita.com/bezeklik/items/0b1b54bc944804420501)
* [CentOS 7.4 で Docker の Redmine を動かす - Qiita](https://qiita.com/bezeklik/items/d3c82926da104ef0c5a3)
* [Redmine を Docker 公式イメージで運用する - Qiita](https://qiita.com/bezeklik/items/b5c39136a8db23e2e81c)