VPSにRuby on Rails環境を構築する。その2 Apache+passengerの設定

さて、前回はrbenvでruby とrailsのインストールを行いました。

今回はApache+passengerの設定を行います。

passengerは前回書いたようにbundle installで一緒にインストールしています。

まずは以下コマンドを実行

passenger-install-apache2-module

と思いきや、コマンドがありません、と怒られてしまいました。
どうやらパスが通ってないようです。

ということで、フルパスを指定して実行します。
まずはfindで実行ファイルを探します。

sudo find / -name passenger-install-apache2-module

/home/user/.rbenv/shims/passenger-install-apache2-module
/home/user/.rbenv/versions/1.9.3-p385/bin/passenger-install-apache2-module
/home/user/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/bin/passenger-install-apache2-module

いました。
ということで、フルパス実行 どーん。

sudo /home/user/.rbenv/versions/1.9.3-p385/bin/passenger-install-apache2-module

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

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.

来ました。
で、このままインストール
うまくいきました。

続いて、apacheの設定
まずはconfファイルを設定します。
ここからはrootユーザで行きます。sudoでもいいですが。。

//移動
cd /etc/httpd/conf.d

//ファイルを新たに作ります。
vi mod_passenger.conf

//以下を書き込み。これはpassenger-install-apache2-moduleを実行すると出てきますので、それをコピぺ
LoadModule passenger_module /home/user/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
PassengerRoot /home/user/.rbenv/versions/1.9.3-p385/lib/ruby/gems/1.9.1/gems/passenger-3.0.19
PassengerRuby /home/user/.rbenv/versions/1.9.3-p385/bin/ruby

続いてhttpd.confの設定
なのだけれど、私のサーバはバーチャルホスト設定しているので
vhost.confに以下のように記載します。

<VirtualHost *:80>
    DocumentRoot "/var/www/html/aaaa/myproject/public"
    ServerName www.prime-architect.co.jp
    RailsEnv production
   <Directory "/var/www/html/aaaa/myproject/public">
      Options FollowSymLinks
      order deny,allow
      allow from All
    </Directory>
</VirtualHost>


これでapacheを再起動すればOKです。

あとはrake db:migrateなどで適当にdb作ればうまくいくはず?
ということで、これからやってみます。