とんちゃんといっしょ

Cloudに関する技術とか日常とかについて書いたり書かなかったり

RailsアプリをPassengerとApacheの連携で動かす

現在うちのサーバはお姉様が友達と作ったサイトがApache上に生きている。
RailsMongrelで動かすといろいろとめんどくさそうなので、
Passengerを使ってApache上で動かすことに。


gemでpassengerをインストールして、
passenger-install-apache2-moduleコマンドでApacheモジュールのビルドとインストール

# gem install passenger
# passenger-install-apache2-module
Welcome to the Passenger Apache 2 module installer.



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をぽちっと押すとコンパイル開始。
コンパイルが終わるとコンフィグをこんな感じでhttpd.confに書けといわれる

The Apache 2 module was successfully installed.

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

   LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-2.2.4/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-2.2.4
   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.

あとアプリケーションの設置場所とかを指定するサンプルが表示される。

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:

   
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
   

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

  /usr/lib64/ruby/gems/1.8/gems/passenger-2.2.4/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.

このままの設定だとDocumentRootの引数が2つあんぞボケ!って怒られる。

/ete/init.d/httpd configtest
Syntax error on line 958 of /etc/httpd/conf/httpd.conf:
DocumentRoot takes one argument, Root directory of the document tree

原因はコメント部分。

      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!

なのでこいつを削る。

      DocumentRoot /somewhere/public

でもこれだとRailsアプリしか動かなくなるので問題。
というわけで以下の部分をコメントアウトしてRailsBaseURIを追加

#   
#      ServerName www.yourhost.com
#      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
#   
RailsBaseURI /redmine

次に設定したDocumentRoot内にRedmineへのシンボリックリンクを作成

# cd /var/www/html
# ln -s /usr/local/rails/redmine/public redmine

参考サイトだとapri/config/environment.rbに設定を追加していたけど、
今使っているRails 2.3.3だと追加したらエラーが出たので追加はしないでおく。
これで無事に普通のHTMLとRailsアプリの共存に成功。


参照:
Apache上でRuby on Railsアプリケーションを動かす/Passenger(mod_rails for Apache)の利用 — Redmine.JP
http://maskana.homedns.org/rails/pro/body/142