AB Lab

abgata20000 blog.

Rubyをapacheで稼働する

passengerをインストール

1
2
3
4
5
6
7
8
9
10
11
12
gem install passenger

passenger-install-apache2-module
# パスとおっていない場合は場所を探す

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

sudo yum install -y curl-devel

/usr/local/rbenv/versions/2.0.0-p247/bin/passenger-install-apache2-module

# 3回くらい質問されるがとりあえずenter連打

インストール完了後のコメント

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
The Apache 2 module was successfully installed.

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

   LoadModule passenger_module /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17/buildout/apache2/mod_passenger.so
   PassengerRoot /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17
   PassengerDefaultRuby /usr/local/rbenv/versions/2.0.0-p247/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 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
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /somewhere/public
      <Directory /somewhere/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
      </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/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17/doc/Users guide Apache.html

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

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

apacheの設定ファイルを変更白みたいなことが書いてあるので変更する

1
vim /etc/httpd/conf.d/passenger.conf
/etc/httpd/conf.d/passenger.conf
1
2
3
LoadModule passenger_module /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.17
PassengerDefaultRuby /usr/local/rbenv/versions/2.0.0-p247/bin/ruby

apahceの設定ファイルでドキュメントルート、バーチャルホストを変更

1
vim /etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.conf
1
DocumentRoot /var/www/ruby/public

ドキュメントルートのディレクトリ作成

1
2
3
4
5
cd /var/www
mkdir ruby
cd ruby
mkdir public
mkdir tmp

実行用の設定ファイル作成

1
vim config.ru
config.ru
1
2
3
4
5
6
require 'bundler'
Bundler.require

require './app'

run App

実行用ファイルの作成

1
2
3
4
5
6
7
8
9
class App < Sinatra::Base
  register Sinatra::Reloader

  get '/' do
      #
      'hello sinatra by apache.'

  end
end

webブラウザ等でアクセスしてみる