ConoHa VPS に Redmine 6 をインストール

ConoHa VPS に Redmine 6 をインストールする方法をご紹介します。

最近、安いし使いやすいと話題の「ConoHa VPS」にプロジェクト管理ツールとしては老舗の Redmine をインストールしました。

ConoHa VPS にはもともと Redmine のテンプレートが用意されているので、それを利用すればとても簡単に Redmine を使い始めることができます。しかし、この方法で使える Redmine が 5.0.6 です。今回はバージョン 6 系が使いたいという要望でしたので、自力でインストールすることにしました。

基本的な手順は「Redmine 6.0 をUbuntu 24.04 LTSにインストールする手順 | Redmine.JP Blog」のサイトを参考にして進めますが、こちらの記事はデータベースに PostgreSQL を使っていて、僕は MySQL 8 を使いたいので、一部違うところが出てきます。

では頑張っていきましょう。

ConoHa VPS でサーバー構築

ConoHa VPS」を契約したら、以下のように OS テンプレートを利用して「Ubuntu 24.04」の構成でサーバーを起動します。

20250418140035

VPS にログイン

VPSサーバーを構築する時に設定した root ユーザーを使ってサーバーにSSHでログインします。IP アドレスは ConoHa VPS の管理画面で確認できます。

ssh root@your_ip_address
20250418153125

Redmine 用のユーザーを作成

初めは root ユーザーしかなさそうですので、Redmine 用のユーザーを作成します。

adduser redmine

パスワードを設定した後、Full Nameなどの情報を聞かれますが、全部空のままエンターでOKです。

Changing the user information for redmine
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n]

redmine ユーザーのグループを調整します。

# sudo グループに追加
usermod -aG sudo redmine

# Apache のグループに追加
usermod -aG www-data redmine

Redmine ユーザーに切り替え

ここで Redmine ユーザーに切り替えておきます。

# redmine ユーザーに切り替え
su - redmine

# 確認(redmine と表示されればOK)
whoami

# sudo の確認(redmine のパスワードを入力し root と表示されればOK)
sudo whoami

これ以降の作業は redmine ユーザーで行います。

ja_JP.UTF-8ロケールの作成

こちらの作業は念の為やっておきます。

sudo apt install -y language-pack-ja
sudo locale-gen ja_JP.UTF-8

Redmine に必要なパッケージをインストール

Redmine を動かすのに必要なパッケージをインストールします。インストールする内容はコマンドの上のコメントに書いておきます。

# パッケージリストを更新
sudo apt update

# RubyとPassengerのビルドに必要な開発ツールやヘッダファイル
sudo apt install -y build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev libffi-dev

# MySQL 8 とヘッダファイルのインストール
sudo apt install -y mysql-server libmysqlclient-dev

# Apache2とその開発用パッケージ
sudo apt install -y apache2 apache2-dev

# 日本語フォント(ガントチャートなどで必要)
sudo apt install -y imagemagick fonts-ipafont

# その他のツール(Redmineのソース取得などに使用)
sudo apt install -y subversion git

Rubyのインストール

次は Ruby のインストールです。

# Rubyの公式サイトからバージョン3.3.6のソースコードをダウンロード
curl -O https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.6.tar.gz

# ダウンロードしたアーカイブを展開
tar xvf ruby-3.3.6.tar.gz

# 展開したディレクトリへ移動
cd ruby-3.3.6

# configureスクリプトを実行(ドキュメントのインストールを無効化)
./configure --disable-install-doc

# ソースコードをコンパイル(時間がかかります)
make

# コンパイルしたRubyをシステムにインストール
sudo make install

# 作業ディレクトリから抜ける
cd ..

# インストールされたRubyのバージョンを確認
ruby -v

MySQL 8の設定

次は MySQL 8 の設定をしていきましょう。

# MySQLのrootユーザーとしてログイン(パスワードは不要です)
sudo mysql -u root

Redmine用のデータベースとユーザーを作成していきます。

# Redmine用のデータベースをUTF8MB4で作成(絵文字対応)
CREATE DATABASE redmine CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

# Redmine用のユーザーを作成(パスワードを設定)
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'ここにパスワードを入れてください';

# ユーザーにすべての権限を付与
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
GRANT SYSTEM_VARIABLES_ADMIN, SESSION_VARIABLES_ADMIN ON *.* TO 'redmine'@'localhost';

# 設定を反映
FLUSH PRIVILEGES;

# MySQL から抜ける
exit

Redmineのインストールと設定

次に Redmine をインストールします。

# Redmineを配置するディレクトリを作成
sudo mkdir /var/lib/redmine

# ディレクトリの所有者をredmineユーザーに変更
sudo chown www-data:www-data /var/lib/redmine

# redmineユーザーに切り替えてダウンロードを実行(rootでの実行は非推奨)
sudo -u www-data svn co https://svn.redmine.org/redmine/branches/6.0-stable /var/lib/redmine

データベースと繋ぐ設定ファイルを作成します。サンプルファイルは config/database.yml.example にあるので、それをコピーして編集してもOKです。

# database.yml を作成
cat << 'EOF' > /var/lib/redmine/config/database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "ここにデータベース作成時に設定したパスワード"
  encoding: utf8mb4
  variables:
    transaction_isolation: READ-COMMITTED
    innodb_strict_mode: 1
EOF

# 所有者とパーミッションを変更
sudo chown www-data:www-data /var/lib/redmine/config/database.yml
sudo chmod 600 /var/lib/redmine/config/database.yml

Redmineの設定ファイル(メールとフォント)を作成します。ここではSMTPでメールを送る設定をしていますので、その部分は適宜書き換えてください。

サンプルファイルは config/configuration.yml.example にあるので、それをコピーして編集してもOKです。

# configuration.yml を作成(メールとフォントを設定)
cat << 'EOF' > /var/lib/redmine/config/configuration.yml
production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "mail.example.com(メールサーバー)"
      port: 465
      domain: "example.com(メールサーバーのドメイン)"
      authentication: :login
      user_name: "info@example.com"
      password: "メールアカウントのパスワード"
      ssl: true

  minimagick_font_path: /usr/share/fonts/opentype/ipafont-mincho/ipam.ttf
EOF

# パーミッションを変更
sudo chown www-data:www-data /var/lib/redmine/config/configuration.yml
sudo chmod 600 /var/lib/redmine/config/configuration.yml

Redmine ディレクトリに移動して Gem をインストールします。

ちなみに、Gem(ジェム)とは Ruby で作られたライブラリやパッケージのことです。

# redmineディレクトリへ移動
cd /var/lib/redmine

# bundlerの不要なグループを除外して設定(redmineユーザーで実行)
sudo bundle config set --local without 'development test'

# 必要なgemをインストール(redmineユーザーで実行)
sudo bundle install

Redmine の初期設定

ここは参考サイトのまま実行します。

# セッション改ざん防止用の秘密鍵を作成
sudo -u www-data bin/rake generate_secret_token

# データベースのテーブルを作成
sudo -u www-data bin/rake db:migrate RAILS_ENV="production"

Passenger のインストールと Apache の設定

Passenger(Phusion Passenger) とは、Ruby on Rails や Python、Node.js などのアプリケーションを Apache や Nginx 上で動かすためのアプリケーションサーバーです。

Apache や Nginx は静的なHTMLやPHPには対応していても、Ruby on Rails 製のアプリケーションである Redmine を直接実行することはできません。

そのため、Passengerが仲介役として間に入り、Apacheの中でRailsアプリを実行できるようにしてくれます。

# ドキュメントなしで passenger をインストール
sudo gem install passenger -N

# Apache向けのPassengerモジュールを自動インストール(Rubyのみ)
sudo passenger-install-apache2-module --auto --languages ruby

# Apacheに追加すべき設定内容をApacheの設定ファイルとして書き出し
passenger-install-apache2-module --snippet | sudo tee /etc/apache2/conf-available/redmine.conf > /dev/null

上で作成した Apache の設定ファイルに少し追記します。

sudo vi /etc/apache2/conf-available/redmine.conf

このコマンドでエディタが開くので、i を押して挿入モードにし、先頭に下記の設定を追加し、 escキーを押してから :wq で保存します。

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

続いて/etc/apache2/sites-enabled/000-default.conf を編集します。

なお、ここでは VPS を Redmine 専用に使うのを前提としていますが、 https://example.com/redmine/ のようにサブディレクトリで運営する場合は、参考サイトの「パターン2: サブディレクトリでRedmineを実行」の項を参照してください。

sudo vi /etc/apache2/sites-enabled/000-default.conf

そして、

DocumentRoot /var/www/html

とあるところを、

DocumentRoot /var/lib/redmine/public

と編集し、 escキーを押してから :wq で保存します。

そして以下の手順で設定ファイルを Apache に読み込ませます。

# Redmine 用の Apache 設定ファイル(/etc/apache2/conf-available/redmine.conf)を有効化
sudo a2enconf redmine

# Apache 設定ファイルの構文チェックを実行(「Syntax OK」以外のメッセージが出たらそれに合わせて修正)
apache2ctl configtest

# Apache を再読み込みして設定を反映
sudo systemctl reload apache2

アセットのコンパイル

以下の手順でCSSやJavaScriptをコンパイルします。

# Redmine のルートディレクトリへ移動
cd /var/lib/redmine

# アセットのプリコンパイル
sudo -u www-data bundle exec rake assets:precompile RAILS_ENV=production

ここまできたら一度 Redmine を開いてみましょう。サーバーのIPアドレスにアクセスすると Redmine が開けるハズです。

トラブルシューティング

もし Redmine が「ERR_CONNECTION_REFUSED」で開けなかったら、以下を順に確認していきましょう。

Apache が動いているか確認

# Apacheが動いているか確認
sudo systemctl status apache2

緑色で「active (running)」と出れば OK です。もし停止していたら以下のコマンドで起動します。

sudo systemctl start apache2

ポート 80(HTTP)が開放されているか確認

sudo ss -tuln | grep ':80'

# tcp   LISTEN 0      511                                       *:80               *:*
# のように「:80」が出力されれば OK

ファイアウォールの確認

sudo ufw status

# 出力結果 (NG)
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)

もし上記のように出力結果に「Apache」が入っていなければ HTTP へのアクセスがブロックされています。以下のコマンドで HTTP/HTTPS を許可しましょう。

sudo ufw allow 'Apache Full'

# 出力結果 (OK)
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
Apache Full                ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Apache Full (v6)           ALLOW       Anywhere (v6)

Let’s Encrypt(Certbot)のインストール

次は SSL でアクセスできるように Let’s Encrypt(Certbot)をインストールします。

redmine.example.com というドメインをこのサーバーに割り当てた前提で進みます。

Certbot をインストール(snap経由)

# パッケージリストを最新に更新(後から追加で行うことも想定)
sudo apt update

# Snapパッケージマネージャーをインストール(Certbotをsnap経由で入れるため)
sudo apt install snapd -y

# snapのコアパッケージをインストール(snapの基本機能)
sudo snap install core

# snapのコアパッケージを最新に更新
sudo snap refresh core

# CertbotをSnapでインストール(--classic オプションで従来の方式を許可)
sudo snap install --classic certbot

# certbot コマンドを /usr/bin/certbot にリンクして、どこでも使えるようにする
sudo ln -s /snap/bin/certbot /usr/bin/certbot

Apache プラグインで証明書発行

Apacheサーバーの設定を元に、Let's Encrypt のSSL証明書を取得して自動設定します。対話形式でドメイン名の選択やHTTPSリダイレクトの有無などを聞かれます。

sudo certbot --apache

このコマンドを実行した後の流れは以下のような感じです。選択肢の答えは適宜変えてください。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address or hit Enter to skip.
 (Enter 'c' to cancel): メールアドレス

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at:
https://letsencrypt.org/documents/LE-SA-v1.5-February-24-2025.pdf
You must agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y(僕はYを入力)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N(僕はNを入力)
Account registered.
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): redmine.example.com                    
Requesting a certificate for redmine.example.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/redmine.example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/redmine.example.com/privkey.pem
This certificate expires on 2025-07-17.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for redmine.example.com to /etc/apache2/sites-available/000-default-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://redmine.example.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

自動更新が有効か確認

sudo systemctl list-timers | grep certbot

# 「snap.certbot.renew.timer」というのが表示されればOK

設定ファイルを確認

cat /etc/apache2/sites-enabled/000-default-le-ssl.conf

これで表示された内容の中に以下のような記述があればOKです。

ServerName redmine.example.com
SSLCertificateFile /etc/letsencrypt/live/redmine.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/redmine.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf

最後に念の為Apacheを再起動しておきます。

sudo systemctl reload apache2

これで https://redmine.example.com/ でアクセスできるようになったはずです!

Redmine にログイン

ようやく辿り着いたRedmineにログインしてみましょう。

ログイン名もパスワードも「 admin 」でログインできますので、すぐに安全なパスワードに変更しましょう。

20250419073500

日本語でも見やすいテーマに変更

Redmine の初期状態は英語向けのデザインになっています。これを日本語でも読みやすく、かつアイコンがついて親しみやすくなる「farend fancy」というテーマに切り替えたいと思います。

まずは以下のコマンドでテーマをインストールします。

# Redmineのインストールディレクトリに移動
cd /var/lib/redmine

# Git 経由でテーマをインストール
git clone https://github.com/farend/redmine_theme_farend_fancy.git themes/farend_fancy

Redmine に戻って、画面一番上のメニューバーの「管理」で管理メニューに移動、そして「設定」→「表示」とすすみ、「テーマ」で「Fare fancy」を選択して「保存」すればテーマが反映されるはずです。

20250419074905
20250419075016

僕の場合は上記の手順だけだと表示が崩れました。なので以下の手順を実行したらちゃんと表示されました。

# Redmineのインストールディレクトリに移動
cd /var/lib/redmine

# アセット関係をコンパイル
sudo -u www-data RAILS_ENV=production bundle exec rake assets:precompile

# Apacheの再起動
sudo systemctl restart apache2

以上です。お疲れ様でした!

Published 2025-04-19
Updated 2025-04-19

⚡️ 話題の一冊 ⚡️