Rubyを入れる(rbenvの導入)
rbenvで入れます.
rootへrbenvを入れますが, まずは環境を整えます.
$ sudo yum install git gcc gcc-c++ openssl-devel readline-devel
rbenvのリポジトリをclone. システム全体へ導入するので/usr/localへ入れます.
$ sudo git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv
rootへ昇格します.
$ su -
rbenv.shを作成します.
# vi /etc/profile.d/rbenv.sh # 以下を記述 export RBENV_ROOT="/usr/local/rbenv" export PATH="${RBENV_ROOT}/bin:${PATH}" eval "$(rbenv init --no-rehash -)"
設定ファイルを読み直します.
# source /etc/profile.d/rbenv.sh
ruby-buildを導入していきます.
# mkdir -p /usr/local/rbenv/plugins # cd /usr/local/rbenv/plugins # git clone https://github.com/sstephenson/ruby-build.git ./ruby-build # cd ./ruby-build/ # ./install.sh
ようやくrubyの導入.
まずはrbenvで入れられるrubyのリストを表示します.
# rbenv install -l
今回は2.5.0にします.
# rbenv install 2.5.0 # rbenv global 2.5.0
最後にバージョンを確認.
ruby -v
SELinuxを無効にする
ごめんなさいごめんなさいごめんなさい.
# vi /etc/selinux/config # 以下を変更 #SELINUX=enforcing SELINUX=disabled
Passengerを入れる
gemでとりあえず投入.
# gem install passenger
続いてapacheモジュールの方も入れる.
# passenger-install-apache2-module
TUIが表示されるので, 1 => Ruby でEnter
一度abortします.
不足しているライブラリが表示されるので(親切!)インストールします.
# yum -y install libcurl-devel httpd httpd-devel apr-devel apr-util-devel
再度挑戦.
# passenger-install-apache2-module
入りました.
apacheの設定のスニペットが表示されます.
見逃しても以下で再表示できます.
# passenger-install-apache2-module --snippet LoadModule passenger_module /usr/local/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/passenger-5.2.1/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/local/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/passenger-5.2.1 PassengerDefaultRuby /usr/local/rbenv/versions/2.5.0/bin/ruby </IfModule>
/etc/htpd/conf.dの下にpassenger.confを作ります. 上記のスニペットをコピペします.
# passenger-install-apache2-module --snippetの内容 LoadModule passenger_module /usr/local/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/passenger-5.2.1/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/local/rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/passenger-5.2.1 PassengerDefaultRuby /usr/local/rbenv/versions/2.5.0/bin/ruby </IfModule> # これはついで # 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" # virtualhostの設定 <VirtualHost *:80> # ドメイン ServerName ドメイン名 # アプリのルート DocumentRoot "/var/www/apps/sample_app/public" RackEnv production </VirtualHost>
設定ファイルをチェック.
# apachectl configtest AH00112: Warning: DocumentRoot [/var/www/apps/sample_app/public] does not exist Syntax OK
apacheを再起動
# apachectl restart
アプリの設定
とりあえずbundlerを入れます.
# gem install bundler
passenger.confで指定したディレクトリを作ります.
tmpはpassengerのリロードに使います.
# mkdir -p /var/www/apps/sample_app/public # mkdir -p /var/www/apps/sample_app/tmp
アプリのディレクトリへ移動して以下の様にアプリを作っておきます.
# cd /var/www/apps/sample_app
アプリ本体.
# app.rb require 'sinatra' get '/' do 'Hello World!' end
rackupファイル.
# config.ru require File.expand_path(File.dirname(__FILE__)) + '/app' run Sinatra::Application
Gemfile
source "https://rubygems.org" gem 'sinatra'
最終的にディレクトリ構成はこんな感じ.
# pwd /var/www # tree . . ├ apps │ └ sample_app │ ├ app.rb │ ├ config.ru │ ├ Gemfile │ ├ Gemfile.lock │ ├ public │ └ tmp ├ cgi-bin └ html
bundleを実行
# bundle install
ブラウザでアクセスすれば挨拶されます.
いやー, これ長い.