ArchLinux 2017.10.01: プロジェクト管理ツールのRedmineをインストールする

Redmineをインストールする手順を記載します。

1 Redmineをインストールする

以下のスクリプトでRedmineをインストールします。

  • MYSQL_PASSWDはMySQLで使うrootユーザのパスワードです。
  • REDMINE_PASSWDはMySQLで使うredmineユーザのパスワードです。
#!/bin/sh

set -e

[ -z "${MYSQL_PASSWD}" ] && MYSQL_PASSWD=mysql
[ -z "${REDMINE_PASSWD}" ] && REDMINE_PASSWD=redmine

mysql_install()
{
  sudo pacman -Sy --noconfirm mariadb

  # Install database.
  sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

  sudo systemctl enable mariadb
  sudo systemctl start mariadb

  # Password configuration.
  cat <<EOF | sudo mysql_secure_installation

y
${MYSQL_PASSWD}
${MYSQL_PASSWD}
n
y
y
y
EOF

  # Create user and database for redmine.
  cat <<EOF | sudo mysql -uroot -p${MYSQL_PASSWD}
CREATE DATABASE redmine CHARACTER SET UTF8;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY '${REDMINE_PASSWD}';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
EOF
}

redmine_install()
{
  sudo pacman -Sy --noconfirm git base-devel
  git clone https://aur.archlinux.org/redmine.git
  cd redmine
  makepkg -s --noconfirm
  sudo pacman -U --noconfirm ./*.pkg.tar.xz
  cd ..

  # BUG: Current ruby-2.4 has a issue "stack level too deep" when running
  # "bundle exec rake db:migrate". This script will use ruby-2.3.
  sudo pacman -Sy --noconfirm ruby2.3 ruby2.3-bundler
  for f in ruby gem rake bundle; do
    sudo ln -s "$(which ${f}-2.3)" /usr/bin/"${f}"
  done

  # Ruby on Rails.
  cd /usr/share/webapps/redmine/
  cat <<EOF | sudo tee config/database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "${REDMINE_PASSWD}"
  encoding: utf8
EOF
  sudo bundle install --without development test
  sudo RAILS_ENV=production bundle exec rake generate_secret_token
  sudo RAILS_ENV=production bundle exec rake db:migrate
  echo "en" | \
    sudo RAILS_ENV=production bundle exec rake redmine:load_default_data
  sudo chown -R http:http files log tmp public/plugin_assets
}

apache_install()
{
  sudo pacman -Sy --noconfirm apache
  sudo systemctl enable httpd

  # ssl configuration.
  # Country Name (2 letter code) [AU]:
  # State or Province Name (full name) [Some-State]:
  # Locality Name (eg, city) []:
  # Organization Name (eg, company) [Internet Widgits Pty Ltd]:
  # Organizational Unit Name (eg, section) []:
  # Common Name (e.g. server FQDN or YOUR name) []:
  # Email Address []:
  cat <<EOF | sudo openssl req -new -x509 -nodes -newkey rsa:4096 -days 1095 \
                   -keyout /etc/httpd/conf/server.key \
                   -out /etc/httpd/conf/server.crt
AU
Some-State
city
company
section


EOF
  sudo sed -i /etc/httpd/conf/httpd.conf \
       -e 's/^#LoadModule ssl_module/LoadModule ssl_module/g' \
       -e 's/^#LoadModule socache_shmcb_module/LoadModule socache_shmcb_module/g'
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
Include conf/extra/httpd-ssl.conf
EOF

  # rewrite configuration.
  sudo sed -i /etc/httpd/conf/httpd.conf \
       -e 's/^#LoadModule rewrite_module/LoadModule rewrite_module/g'
  cat << EOF | sudo tee /etc/httpd/conf/extra/redirect-to-https.conf
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
EOF
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
Include conf/extra/redirect-to-https.conf
EOF

  # passenger configuration.
  sudo gem install --no-user-install passenger
  cd /opt/ruby2.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.11/bin
  echo "1" | sudo ./passenger-install-apache2-module
  cat << EOF | sudo tee /etc/httpd/conf/extra/passenger.conf
PassengerRoot /opt/ruby2.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.11
PassengerDefaultRuby /opt/ruby2.3/bin/ruby-2.3
PassengerDefaultUser http
RailsBaseURI /redmine
EOF
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
LoadModule passenger_module \
/opt/ruby2.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.11/buildout/apache2/mod_passenger.so
Include conf/extra/passenger.conf
EOF

  # redmine configuration.
  sudo ln -s /usr/share/webapps/redmine/public /srv/http/redmine
  cat << EOF | sudo tee /etc/httpd/conf/extra/redmine.conf
<Directory /redmine>
  Options FollowSymLinks
  PassengerResolveSymlinksInDocumentRoot on
  AllowOverride None
</Directory>
EOF
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
Include conf/extra/redmine.conf
EOF

  sudo systemctl restart httpd
}

redmine_main()
{
  mysql_install
  redmine_install
  apache_install
}

redmine_main

2 Redmineにアクセスする

以下のURLでRedmineにアクセスします。ブラウザでこのページの証明書を許可してください。adminユーザのデフォルトパスワードはadminです。

https://<server>/redmine

0001_Redmine.png