CentOS6.2にPassengerをインストールしてApacheと紐付けます。
■前提条件
・CentOS release 6.2 (Final)
・Ruby 2.1.2
・Rails 4.1.2
・複数のRailsアプリケーションを一台のサーバーで稼動させることは想定していない
・Railsアプリケーション以外を稼働させることは想定していない
■事前準備
足りないパッケージをインストールします(すでにインストール済なら飛ばします)。
# yum -y install curl-devel httpd-devel
■インストール
(1)Passengerをインストールします。
# gem install --no-ri --no-rdoc passenger Fetching: daemon_controller-1.2.0.gem (100%) Successfully installed daemon_controller-1.2.0 Fetching: passenger-4.0.45.gem (100%) Building native extensions. This could take a while... Successfully installed passenger-4.0.45 2 gems installed
(2)Apacheモジュールをインストールします。
# passenger-install-apache2-module Welcome to the Phusion Passenger Apache 2 module installer, v4.0.45. 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キーを押下します。
-------------------------------------------- Which languages are you interested in? Use <space> to select. If the menu doesn't display correctly, press '!' ‣ ⬢ Ruby ⬡ Python ⬡ Node.js ⬡ Meteor
言語を訊いてくるので、ここではRubyのみ選択(上下カーソルキーで移動、Spaceキー押下で選択/解除)してEnterキーを押下します。
linking shared-object passenger_native_support.so -------------------------------------------- Almost there! Please edit your Apache configuration file, and add these lines: LoadModule passenger_module /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45 PassengerDefaultRuby /usr/local/rbenv/versions/2.1.2/bin/ruby </IfModule> After you restart Apache, you are ready to deploy any number of web applications on Apache, with a minimum amount of configuration! Press ENTER to continue.
少し時間がかかりますが、ここで止まるので、
<IfModule mod_passenger.c> PassengerRoot /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45 PassengerDefaultRuby /usr/local/rbenv/versions/2.1.2/bin/ruby </IfModule>
をコピーしてどこかに保持し、Enterキーを押下します。
-------------------------------------------- Deploying a web application: an example Suppose you have a web 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 # Uncomment this if you're on Apache >= 2.4: #Require all granted </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.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/doc/Users guide Apache.html https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.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.
ここでインストールが終わります。
<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 # Uncomment this if you're on Apache >= 2.4: #Require all granted </Directory> </VirtualHost>
をコピーしてどこかに保持し、Enterキーを押下します。
(3)passengerが組み込まれたかどうか確認します。
# apachectl -M | grep passenger
passenger_module (shared) Syntax OK
大丈夫そうです。
(4)httpd.confを編集します。
# vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80の行のコメントを外します。
NameVirtualHost *:80
最終行に先程コピーした以下の内容を貼り付けます。
<IfModule mod_passenger.c> PassengerRoot /usr/local/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45 PassengerDefaultRuby /usr/local/rbenv/versions/2.1.2/bin/ruby </IfModule>
(5)vhost.confを生成します。
# vi /etc/httpd/conf.d/vhost.conf
最終行に先程コピーした以下の内容を貼り付けます。
<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 # Uncomment this if you're on Apache >= 2.4: #Require all granted </Directory> </VirtualHost>
www.yourhost.com や /somewhere/public はあくまでも例ですので、環境に応じて実在する値に書き換えてください。なお、Passengerはデフォルトだとproductionモードで動作しますので、Rails側がdevelopmentのモードの場合はvhost.confに下記を追記します。
RailsEnv development
(6)apacheを起動します。
# service httpd start
(7)http://サーバーのアドレス/ で正しく参照できたら終了です。