LoginSignup
10
12

More than 5 years have passed since last update.

RedmineをDebianに導入する

Last updated at Posted at 2014-10-12

Debian(Wheezy)にRedmineを入れてみようかな?

  • Debian(Wheezy)
  • Redmine
  • MySQL
  • Ruby 1.9.3

Redmineの導入

準備

RubyとRedmineを使うための準備を行います。

root# apt-get install git
root# apt-get install make
root# apt-get install g++
root# apt-get install libssl-dev
root# apt-get install libreadline-gplv2-dev
root# apt-get install zlib1g-dev
root# apt-get install libyaml-dev
root# apt-get install build-essential
root# apt-get install curl
root# apt-get install imagemagick
root# apt-get install libmagickcore-dev
root# apt-get install libmagickwand-dev

Rubyのインストール

インターネット上からrvmのパッケージをダウンロードし、rvmをシステムに導入します。
Ruby自体はrvmを使って目的のバージョンをシステムに導入します。

root# curl -L https://get.rvm.io | bash -s stable
root# source /etc/profile.d/rvm.sh
root# rvm install 1.9.3
root# ruby -v
ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-linux]

※Ruby1.9.3のリビジョンは異なるかもしれません。

MySQLのインストール

すでにMySQLが導入済みの場合は、下記のコマンドを実行する必要はないです。

root# apt-get -y install mysql-server

ただし、RubyからMySQLへ接続するためのアダプタをセットアップするにはlibmysqlclient-devが必要ですので、aptを使ってシステムへインストールを行います。

root# apt-get install -y libmysqlclient-dev

最後にRubyからMySQLへ接続するためのgemライブラリをセットアップします。

root# gem install mysql2
Fetching: mysql2-0.3.16.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.16
Installing ri documentation for mysql2-0.3.16
1 gem installed

bundlerのインストール

Rubyのソフトウェアを管理しやすくするために、先にbundlerを導入します。

root# gem install bundler --no-rdoc --no-ri
Fetching: bundler-1.7.3.gem (100%)
Successfully installed bundler-1.7.3
1 gem installed

Redmineのインストール

Redmineのソースコードをgitから直接取得します。
また、取得したRedmineは /usr/lib/redmine に配置します。

root# git clone https://github.com/redmine/redmine.git redmine
root# cd ./redmine
root# git checkout -b 2.5-stable origin/2.5-stable
root# cd ./../
root# mv ./redmine /usr/lib/
root# cd /usr/lib/redmine
root# bundle install --without development test postgresql sqlite
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will
break this application for all non-root users on this machine.
Please configure your config/database.yml first
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Installing rake 10.1.1
Installing i18n 0.6.11
Installing multi_json 1.10.1
Installing activesupport 3.2.19
Installing builder 3.0.0
Installing activemodel 3.2.19
Installing erubis 2.7.0
Installing journey 1.0.4
Installing rack 1.4.5
Installing rack-cache 1.2
Installing rack-test 0.6.2
Installing hike 1.2.3
Installing tilt 1.4.1
Installing sprockets 2.2.2
Installing actionpack 3.2.19
Installing mime-types 1.25.1
Installing polyglot 0.3.5
Installing treetop 1.4.15
Installing mail 2.5.4
Installing actionmailer 3.2.19
Installing arel 3.0.3
Installing tzinfo 0.3.41
Installing activerecord 3.2.19
Installing activeresource 3.2.19
Installing awesome_nested_set 2.1.6
Using bundler 1.7.3
Installing coderay 1.1.0
Installing rack-ssl 1.3.4
Installing json 1.8.1
Installing rdoc 3.12.2
Installing thor 0.19.1
Installing railties 3.2.19
Installing jquery-rails 2.0.3
Installing net-ldap 0.3.1
Installing ruby-openid 2.3.0
Installing rack-openid 1.4.2
Installing rails 3.2.19
Installing redcarpet 2.3.0
Installing rmagick 2.13.3
Your bundle is complete!
Gems in the groups development, test, postgresql and sqlite were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Post-install message from rmagick:
Please report any bugs. See https://github.com/gemhome/rmagick/compare/RMagick_2-13-2...master and https://github.com/rmagick/rmagick/issues/18
root# chown www-data:www-data -R /usr/lib/redmine
root# cd /usr/lib/redmine
root# chmod -R 755 files log tmp public/plugin_assets

bundle install --without development test postgresql sqlite ではRedmineのインストールスクリプトを呼び出します。Redmineを実行するために必要な依存関係ライブラリがbundleによってインストールされます。ただし、不要なパッケージはwithoutオプションで除外します。
今回はデータベースにMySQLを使用するので、postgresqlやsqliteのためのパッケージは排除します。

データベースの準備

Redmineが使うデータベース(名前はredmineとします)をMySQLに作成します。
※userやpasswordパラメータには、データベースの作成権限を持つMySQLのユーザーとパスワード

root# mysql --user=root --password=Password --execute="CREATE DATABASE redmine CHARACTER SET utf8 COLLATE utf8_general_ci;"

次に、Redmineがこのデータベースに接続するための設定を記述します。
/usr/lib/redmine/config/database.ymlに記述します。このファイルそのものはRedmineのセットアップには含まれていませんので、自分でファイル自体を作成し、次のような記述を書き込みます。

production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: root
  password: Password
  encoding: utf8

rootを使ってデータベース「redmine」にアクセスしていますが、セキュリティのことを考えると専用のユーザー権限をMySQLに作成して、そのユーザーでアクセスする方がよいでしょう。

セットアップの完了

最後に次のコマンドを入力し、Redmineのセットアップを完了します。

root# rake generate_secret_token
root# RAILS_ENV=production rake db:migrate

コンソールにいろいろとログが表示され、セットアップが完了します。

Webサイトの公開

ApacheでRedmineを公開します。
システムにApacheが導入されていない場合はaptを使って先にインストールを行います。

root# apt-get install -y apache2

passengerの導入

passengerはRoRで作られたアプリケーションをApacheからアクセスするためのモジュールです。

aptを使ってpassengerが動作するためのライブラリもインストールします。

root# gem install passenger --no-rdoc --no-ri
root# apt-get install libcurl4-openssl-dev apache2-threaded-dev libapr1-dev libaprutil1-dev
root# passenger-install-apache2-module

最後にpassengerをapacheのモジュールとしてビルド&インストールします。
途中の設問は、使用するアプリケーションにRubyを選択します。

正常にビルドが完了すると、下記のようなテキストが表示されます。

LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p547/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p547/gems/passenger-4.0.53
     PassengerDefaultRuby /usr/local/rvm/gems/ruby-1.9.3-p547/wrappers/ruby
   </IfModule>

Apacheが受け付けたリクエストをpassengerに処理させるための記述です。
上記の内容を記述したファイルを/etc/apache2/conf.d/passenger.confに配置します。

Redmineの公開設定

Apacheに「http://<あなたのサーバーIP>/redmine」のアドレスへアクセスがあった場合に、Redmineに処理させるための設定を記述します。

/etc/apache2/sites-avaliable/default に既存の設定がありますが、このファイルに下記の内容を記述します。
※DocumentRoot の記述の下あたり

RackBaseURI /redmineという記述を追加します。

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    RackBaseURI /redmine

また、ApacheはDocumentRootに/var/wwwを参照します。
Redmineへのアクセスには/var/www/redmineを参照しようとするので、新保リンクリンクを張ってしまうのがもっとも簡単でしょう。

root# cd /var/www
root# ln -s /usr/lib/redmine/public ./redmine

最後に設定ファイルの変更を適応するために、apacheを再起動します。

root# /etc/init.d/apache2 restart
10
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12