hogehoge foobar Blog Style Beta

Web,Mac,Linux,JavaScript,Perl,PHP,RegExp,Git,Vim,Redmineなど技術的なことのメモや、ちょっと便利そうなものの紹介をしています。

CentOSへRedmine1.1.0をインストール(passenger設定編)

前回のCentOSへのRedmineインストール/設定の続きです。
CentOSへRedmine1.1.0をインストール

今回はRedmine(Ruby on Rails)をApache(passenger)で動かすところまでやります。

前回に引き続き、インストールの大筋については、
www.sakuttoly.com - サクッとCentOS 5.3にRedmine + Passenger環境をインストール
を参考にさせてもらっています。

とりあえずrootになる

前回と同様に、まずはrootになります。

$ su - root
パスワード:
[root@centos ~]# 

いろいろと事前準備

httpd-devel等、必要になるものを事前にインストールしておきます。

httpd-devel gcc-c++ apr-develをインストール
# yum -y install httpd-devel gcc-c++ apr-devel

Installed:
  apr-devel.i386 0:1.2.7-11.el5_5.3                  gcc-c++.i386 0:4.1.2-48.el5          
  httpd-devel.i386 0:2.2.3-43.el5.centos.3          

Dependency Installed:
  apr-util-devel.i386 0:1.2.7-11.el5_5.2     cyrus-sasl-devel.i386 0:2.1.22-5.el5_4.3    
  db4-devel.i386 0:4.3.29-10.el5_5.2         expat-devel.i386 0:1.95.8-8.3.el5_5.3       
  libstdc++-devel.i386 0:4.1.2-48.el5        openldap-devel.i386 0:2.3.43-12.el5_5.3     
  pkgconfig.i386 1:0.21-2.el5               

Complete!

passengerのインストール(gem)

準備が終わったら、passengerをインストールします。
passengerはgemからインストールします。

passengerをインストール
# gem install passenger

Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-0.2.5
Successfully installed spruz-0.2.2
Successfully installed file-tail-1.0.5
Successfully installed passenger-3.0.2
5 gems installed

passenger-install-apache2-moduleのインストール/設定(失敗編)

gemでのpassengerのインストールが成功したら、「passenger-install-apache2-module」コマンドを実行します。
コマンドを実行すると、少しだけ対話側のインターフェースが起動されます。

Welcome to the Phusion Passenger Apache 2 module installer, v3.0.2.

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キー」を押して、処理を続行させます。

次に、インストールに必要なモジュールのチェックが実行され、チェックの結果が以下のような形で表示されます。
すでにインストール済みのものは「found」、まだインストールされていないものは「not found」で表示されます。
私の場合「Curl development headers with SSL support... not found」でした。

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Curl development headers with SSL support... not found
 * OpenSSL development headers... found
 * Zlib development headers... found
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * rack... found
 * Apache 2... found at /usr/sbin/httpd
 * Apache 2 development headers... found at /usr/sbin/apxs
 * 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

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キー」を押して、処理を続行させます。

すると、さっき「not found」になっていた「curl-devel」のインストール方法を教えてくれたあとで、対話型インターフェースが終了します。

Installation instructions for required software

 * To install Curl development headers with SSL support:
   Please run yum install curl-devel as root.

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

  /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/doc/Users guide Apache.html

curl-develのインストール

passenger-install-apache2-moduleのインストールの時に教えたもらったとおりに、yumからcurl-develをインストールします。

curl-develをインストール
# yum -y install curl-devel

Installed:
  curl-devel.i386 0:7.15.5-9.el5                                                          

Dependency Installed:
  libidn-devel.i386 0:0.6.5-1.1                                                           

Complete!

passenger-install-apache2-moduleのインストール/設定(成功編)

curl-develのインストールが成功したら、もう一度「passenger-install-apache2-module」コマンドを実行します。

今度はチェックが全て「found」で成功します。

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Curl development headers with SSL support... found
 * OpenSSL development headers... found
 * Zlib development headers... found
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * rack... found
 * Apache 2... found at /usr/sbin/httpd
 * Apache 2 development headers... found at /usr/sbin/apxs
 * 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

チェックが成功すると、そのまま続けてインストールが実行されます。
ガーっとインストールのログが出力されている途中で、以下のような画面が表示されて一旦処理が止まります。

--------------------------------------------
The Apache 2 module was successfully installed.

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

   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2
   PassengerRuby /usr/bin/ruby

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.

上記の

   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2
   PassengerRuby /usr/bin/ruby

という部分について、あとでApacheの設定ファイルへの追記などが必要になるので、メモして残しておきます。

「Enterキー」を押すと、以下のような画面が表示されて、インストールが終了します。

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

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

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <Directory /somewhere/public>
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </Directory>
   </VirtualHost>

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

  /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/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.

これも上記の

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <Directory /somewhere/public>
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </Directory>
   </VirtualHost>

の部分をApacheの設定ファイルへ追記する必要があるので、メモして残しておきます。

Apacheの設定

ひと通りのインストールが終わったので、Apacheの設定をします。

passenger.confの設定(新規作成)

passenger用の設定ファイルを新規作成します。
ファイル名は「/etc/httpd/conf.d/passenger.conf」になります。

ファイルには、さっき最初にメモした内容を記述します。

# vim /etc/httpd/conf.d/passenger.conf

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.2
PassengerRuby /usr/bin/ruby
httpd.confの設定

次にhttpd.confの設定をします。
httpd.confの一番最後に、さっき2番目にメモした内容を記述します。

記述する際、「DocumentRoot」などを環境に合わせて変更します。

また、コメント( # <-- be sure to point to 'public'! 等)についても合わせて削除します。
コメントを削除しない場合、apacheの起動時に以下のようなエラーが発生し、apacheが起動できなくなるので、コメントは必ず削除します。

Apacheの起動エラー

# /etc/init.d/httpd start
httpd を起動中: Syntax error on line 995 of /etc/httpd/conf/httpd.conf:
DocumentRoot takes one argument, Root directory of the document tree
                                                           [失敗]

httpd.confに追記した内容

<VirtualHost *:80>
   ServerName www.yourhost.com
   DocumentRoot /var/www/html/redmine/public
   <Directory /var/www/html/redmine/public>
      AllowOverride all
      Options -MultiViews
   </Directory>
</VirtualHost>
Redmineのオーナーの変更

RedmineをApacheで実行するのに伴い、logディレクトリなどのオーナーの変更が必要になります。
Redmine本体を置いてあるディレクトリに移動し、以下のコマンドでオーナーを変更します。

# chown -R apache:apache files log config/environment.rb 

Apacheの起動/ブラウザからアクセス

ここまでで、インストール/設定が完了したので、Apacheを起動させます。

# /etc/init.d/httpd start
httpd を起動中: httpd: apr_sockaddr_info_get() failed for centos.localdomain
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]

Apacheが正常に起動したら、ブラウザから「http://localhost/ 」などにアクセスし、Redmineのページが表示されれば成功です。

今回参考にしたページ

www.sakuttoly.com - サクッとCentOS 5.3にRedmine + Passenger環境をインストール
http://www.sakuttoly.com/blog/2009/04/redmine_passenger_centos.html

RailsアプリをPassengerとApacheの連携で動かす - 巻き込まれ人生
http://d.hatena.ne.jp/Mazin/20090809/1249798716