LoginSignup
57
55

More than 5 years have passed since last update.

さくらVPS(CentOS)にPassenger+Apache+Sinatra

Last updated at Posted at 2013-09-20

1.Passengerのインストール

% gem install passenger

2.PassengerのApacheモジュールのインストール

# モジュールのインストールに必要なものをインストール
# 自分の環境ではこの4つがなかった
% yum install curl-devel

% yum install httpd-devel

% yum install apr-devel

% yum install apr-util-devel

# passengerのapacheモジュールのインストール
% passenger-install-apache2-module

インストール後、以下のコマンドを実行。

% passenger-install-apache2-module --snippet

# 以下をPassengerの設定で使うので、メモ
LoadModule passenger_module /home/masa2sei/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/passenger-4.0.18/buildout/apache2/mod_passenger.so
PassengerRoot /home/masa2sei/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/passenger-4.0.18
PassengerDefaultRuby /home/masa2sei/.rbenv/versions/1.9.3-p194/bin/ruby

3.Passengerの設定

/etc/htpd/conf.dの下にpassenger.confを以下の内容で作成。
※作成するファイルは拡張子が.confなら、何でもいい。

/etc/httpd/conf.d/passnger.conf
# 2でメモったメッセージ
LoadModule passenger_module /home/masa2sei/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/passenger-4.0.18/buildout/apache2/mod_passenger.so
PassengerRoot /home/masa2sei/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/passenger-4.0.18
PassengerDefaultRuby /home/masa2sei/.rbenv/versions/1.9.3-p194/bin/ruby

# Passengerが追加するHTTPヘッダを削除するための設定。
Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"

# この辺の設定は必要なら
PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerHighPerformance on
PassengerStatThrottleRate 10
# Apacheの文法チェック
% apachectl configtest
Syntax OK

Apacheの再起動

% service httpd restart

4.VirtualHostの設定

/etc/httpd/conf.d/passnger.confに以下を追記。

/etc/httpd/conf.d/passnger.conf
------------------略------------------

<VirtualHost *:80>
  # ドメイン
  ServerName 自分のドメイン
  # sinatraアプリのルート
  DocumentRoot "/var/www/apps/sinatra/sinatra_sample/public"
  RackEnv production
</VirtualHost>

/etc/httpd/conf/httpd.confを編集し、VirtualHostを有効にする。

/etc/httpd/conf/httpd.conf
# コメント解除
# NameVirtualHost *:80
NameVirtualHost *:80

Apacheの再起動

% service httpd restart

5.Sinatraアプリの作成

sinatra.confで指定したsinatraアプリのルートディレクトリの下に以下のようなファイルとディレクトリを作成。
publictmpディレクトリの中はとりあえず、空でOK。

sinatra_sample
        |
        ー config.ru
        |
        ー hello.rb
        |
        ー public/
        |
        ー tmp/
sinatra_sample/hello.rb
require 'sinatra'

get '/' do
  'Hello World!'
end
sinatra_sample/config.ru
require File.expand_path(File.dirname(__FILE__)) + '/hello'
run Sinatra::Application

参照

さくらVPS/CentOS 6.3 Passengerのインストール手順[Apache][Railsサーバへの道]
Linux(CentOS)のApache+PassengerでRuby on Railsを動かす
ModularStyleのSinatraをPassengerで公開

57
55
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
57
55