garbagetown

個人の日記です

Redmine (2)

Redmine.JP のドキュメントでは、redmine をインストール後、WEBrick ではなく Passenger を使って Apache 上で動かすのをオススメするとあるので、ヒマ潰しにやってみる。

Passenger gem のインストール

gem を使って passenger をインストールする。

$ sudo gem install passenger
Building native extensions.  This could take a while...
ERROR:  Error installing passenger:
	ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install passenger
creating Makefile

make
sh: make: not found

Gem files will remain installed in /var/lib/gems/1.8/gems/fastthread-1.0.7 for inspection.
Results logged to /var/lib/gems/1.8/gems/fastthread-1.0.7/ext/fastthread/gem_make.out

いきなりまさかの make 失敗。build 関連のモジュールは以前にインストールしたような気がするのだが、無いと言われているし、たしかに無いので渋々入れる。

$ sudo apt-get install build-essential
パッケージリストを読み込んでいます... 0%
(snip)
以下の特別パッケージがインストールされます:
  dpkg-dev g++ g++-4.3 libstdc++6-4.3-dev make
提案パッケージ:
  debian-keyring g++-multilib g++-4.3-multilib gcc-4.3-doc libstdc++6-4.3-dbg
  libstdc++6-4.3-doc make-doc
以下のパッケージが新たにインストールされます:
  build-essential dpkg-dev g++ g++-4.3 libstdc++6-4.3-dev make
アップグレード: 0 個、新規インストール: 6 個、削除: 0 個、保留: 54 個。
6259kB のアーカイブを取得する必要があります。
この操作後に追加で 22.3MB のディスク容量が消費されます。
続行しますか [Y/n]? y
(snip)
make (3.81-5) を設定しています ...
dpkg-dev (1.14.20ubuntu6) を設定しています ...
libstdc++6-4.3-dev (4.3.2-1ubuntu12) を設定しています ...
g++-4.3 (4.3.2-1ubuntu12) を設定しています ...
g++ (4:4.3.1-1ubuntu2) を設定しています ...
build-essential (11.4) を設定しています ...

できた。もう一度 gem install を実行。

$ sudo gem install passenger
Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed fastthread-1.0.7
Successfully installed passenger-2.2.1
2 gems installed
Installing ri documentation for fastthread-1.0.7...
(snip)
Installing ri documentation for passenger-2.2.1...
Installing RDoc documentation for fastthread-1.0.7...
(snip)
Installing RDoc documentation for passenger-2.2.1...

できた。

Passenger モジュールのインストール

続いて passenger-install-apache2-module を実行して、Apache2 モジュールのビルドとインストールを行う。
画面の指示に従えば容易に処理を完了できます、とのこと。いってみよう。

$ sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module 
Welcome to the Phusion Passenger Apache 2 module installer, v2.2.1.

This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.

なにかおかしなことが起こっても解決方法をアドバイスするから心配するな、と来た。こんな兄貴肌なスクリプトは初めて見た。
とりあえず Enter キーをひっぱたく。

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /var/lib/gems/1.8/bin/rake
 * Apache 2... found at /usr/sbin/apache2
 * Apache 2 development headers... not found
 * fastthread... found
 * Apache Portable Runtime (APR) development headers... not found
 * Apache Portable Runtime Utility (APU) development headers... not found

Some required software is not installed.
But don't worry, this installer will tell you how to install them.

Press Enter to continue, or Ctrl-C to abort.

なんか足りないらしい。兄貴を信じて Enter キーをひっぱたく。

Installation instructions for required software

 * To install Apache 2 development headers:
   Please run apt-get install apache2-prefork-dev as root.

 * To install Apache Portable Runtime (APR) development headers:
   Please run apt-get install libapr1-dev as root.

 * To install Apache Portable Runtime Utility (APU) development headers:
   Please download it from http://httpd.apache.org/
   (APR Utility is an integrated part of Apache.)

If the aforementioned instructions didn't solve your problem, then please take
a look at the Users Guide:

  /var/lib/gems/1.8/gems/passenger-2.2.1/doc/Users guide Apache.html

インストール方法を懇切丁寧に教えてくれた。すげえや兄貴。
最後の APU とかいう奴はよく分からないけど、とりあえず先の二つについては兄貴の言うとおり apt-get を実行。

$ sudo apt-get install apache2-prefork-dev libapr1-dev
パッケージリストを読み込んでいます... 0%
(snip)
状態情報を読み取っています... 完了
以下の特別パッケージがインストールされます:
  comerr-dev libaprutil1-dev libdb4.6-dev libexpat1-dev libkadm55 libkrb5-dev libkrb53
  libldap-2.4-2 libldap2-dev libmysqlclient15-dev libpcre3-dev libpcrecpp0 libpq-dev
  libpq5 libsqlite3-0 libsqlite3-dev libssl-dev libssl0.9.8 uuid-dev zlib1g-dev
提案パッケージ:
  doc-base db4.6-doc krb5-doc krb5-user postgresql-doc-8.3 sqlite3-doc
以下のパッケージが新たにインストールされます:
  apache2-prefork-dev comerr-dev libapr1-dev libaprutil1-dev libdb4.6-dev libexpat1-dev
  libkadm55 libkrb5-dev libldap2-dev libmysqlclient15-dev libpcre3-dev libpcrecpp0
  libpq-dev libsqlite3-dev libssl-dev uuid-dev zlib1g-dev
以下のパッケージはアップグレードされます:
  libkrb53 libldap-2.4-2 libpq5 libsqlite3-0 libssl0.9.8
アップグレード: 5 個、新規インストール: 17 個、削除: 0 個、保留: 67 個。
17.5MB 中 6655kB のアーカイブを取得する必要があります。
この操作後に追加で 43.2MB のディスク容量が消費されます。
続行しますか [Y/n]? y
0% [処理中]              

libaprutil1-dev (1.2.12+dfsg-7) を設定しています ...
apache2-prefork-dev (2.2.9-7ubuntu3) を設定しています ...
Processing triggers for libc6 ...
ldconfig deferred processing now taking place

できた。もう一度、兄貴にお伺いを立ててみる。

$ sudo /var/lib/gems/1.8/bin/passenger-install-apache2-module
(snip)
Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /var/lib/gems/1.8/bin/rake
 * Apache 2... found at /usr/sbin/apache2
 * Apache 2 development headers... found at /usr/bin/apxs2
 * fastthread... found
 * Apache Portable Runtime (APR) development headers... found at /usr/bin/apr-1-config
 * Apache Portable Runtime Utility (APU) development headers... found at /usr/bin/apu-1-config

--------------------------------------------
Compiling and installing Apache 2 module...
(snip)
--------------------------------------------
The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.2.1/ext/apache2/mod_passenger.so
   PassengerRoot /var/lib/gems/1.8/gems/passenger-2.2.1
   PassengerRuby /usr/bin/ruby1.8

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.

あれよあれよという間に Passenger モジュールが入ったらしい。
設定ファイルに書く内容まで教えてくれる兄貴に感銘を受けつつ Enter キーをひっぱたく。

--------------------------------------------
Deploying a Ruby on Rails application: an example

Suppose you have a Ruby on Rails application in /somewhere. Add a virtual host
to your Apache configuration file, and set its DocumentRoot to
/somewhere/public, like this:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips and other useful information:

  /var/lib/gems/1.8/gems/passenger-2.2.1/doc/Users guide Apache.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

バーチャルホストを使う際の設定例が表示されて完了。

Passenger モジュールの有効化

先に兄貴が教えてくれた設定を httpd.conf にそのまま書いても動くはずだが、ここは Ubuntu の流儀に従って passenger.load と passenger.conf を作成して、ここに記述する。
よく知らないけど、そういうものらしい。

$ cd /etc/apache2/mods-available/
$ sudo vi passenger.load
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-2.2.1/ext/apache2/mod_passengger.so

$ sudo vi passenger.conf
PassengerRoot /var/lib/gems/1.8/gems/passenger-2.2.1
PassengerRuby /usr/bin/ruby1.8

設定ファイルを書いたら a2enmod で有効にする。

$ sudo a2enmod passenger
Enabling module passenger.
Run '/etc/init.d/apache2 restart' to activate new configuration!

バーチャルホストの設定はまた今度にして、まずは Apache2 の DocumentRoot を大胆に書き換えてみる。

$ cd /etc/apache2/sites-available
$ sudo cp -p default default.bak
$ sudo vi default
<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   DocumentRoot /var/lib/redmine-0.8.3/public/
   <Directory />
      Options FollowSymLinks
      AllowOverride None
   </Directory>
   <Directory /var/www/>
(snip)

$ sudo /etc/init.d/apache2 restart
 * Restarting web server apache2
 ... waiting    ...done.

Apache2 を再起動したら、http://xxx.xxx.xxx.xxx/ にアクセスして、redmine の画面が表示される事を確認する。