2017年2月4日土曜日

AWS EC2にApache、Passenger、Sinatra環境を構築する


◆ 利用するEC2
t2.small
※メモリは2Gは欲しい



◆ rubyのバージョンアップ
$ sudo yum install -y git gcc gcc-c++ openssl-devel readline-devel
$ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l
$ rbenv -v
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install 2.3.3
$ rbenv global 2.3.3
$ ruby -v



◆ apacheとpassengerの連携
$ gem install passenger
$ sudo yum install libcurl-devel httpd httpd-devel apr-devel apr-util-devel
$ passenger-install-apache2-module
※apacheのconfigへ設定する内容をコピー

$ cd /usr/local/src/mydir/
$ vi hello.rb
require 'sinatra'
get '/' do
  'Hello World!'
end

$ mkdir public
$ mkdir tmp
$ vi config.ru
require 'rubygems'
require 'sinatra'
require File.expand_path '../hello.rb', __FILE__

run Sinatra::Application


$ vi /etc/httpd/conf.d/passenger.conf
LoadModule passenger_module /home/ec2-user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.2/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /home/ec2-user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/passenger-5.1.2
  PassengerDefaultRuby /home/ec2-user/.rbenv/versions/2.3.3/bin/ruby
</IfModule>

Listen 8080

<VirtualHost *:8080>
  DocumentRoot /usr/local/src/bot/line/public
  <Directory /usr/local/src/bot/line/public>
    Require all granted
    Allow from all
    Options -MultiViews
    #Relax Apache security settings
    #AllowOverride all
    #MultiViews must be turned off
    #Options -MultiViews
  </Directory>
</VirtualHost>

$ sudo /etc/init.d/httpd restart



◆ 確認
ブラウザからアクセス
http://x.x.x.x:8080/
500 Internal Server Error

WEBrickによる切り分け

$ ruby hello.rb
`require': cannot load such file -- sinatra


$ gem install bundle
$ vi Gemfile
source 'https://rubygems.org'
gem "sinatra"

$ bundle install
An error occurred while installing pg (0.19.0), and Bundler cannot continue.

$ sudo yum install postgresql postgresql-devel sqlite sqlite-devel
$ bundle install
$ ruby hello.rb
$ sudo /etc/init.d/httpd restart

ブラウザからアクセス
http://x.x.x.x:8080/
500 Internal Server Error

$ tail -f /var/log/httpd/error_log
configuration error:  couldn't perform authentication. AuthType

$ sudo vi /etc/httpd/conf.d/passenger.conf
#以下をいったん無効にする
#Require all granted

改めて、
$ sudo /etc/init.d/httpd restart

ブラウザからアクセス
http://x.x.x.x:8080/
'Hello World!'


(参考)
http://recipes.sinatrarb.com/p/deployment/apache_with_passenger




7 件のコメント:

  1. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..

    Digital Marketing Company in India

    返信削除
  2. This blog having the details of Processes running. The way of running is explained clearly. The content quality is really great. The full document is entirely amazing. Thank you very much for this blog.
    SEO Company in India
    Digital Marketing Company in India

    返信削除
  3. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    GMAT coaching institutes in chennai

    返信削除
  4. Thank you for sharing such a nice and interesting blog with us. I have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog in my dude circle.
    SEO Company in Chennai

    返信削除
  5. Great tips, and awesome way to get exert tips from everyone,not only i like that post all peoples like that post,because of all given information was wonderful

    Best Dental Clinic in Anna Nagar | Best Dental Clinic in Ashok Nagar

    返信削除
  6. Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Digital Marketing Course in Chennai

    返信削除
  7. Thank you for sharing such a nice and interesting blog with us. I have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog in my dude circle.
    Jobs in Chennai
    Jobs in Bangalore
    Jobs in Delhi
    Jobs in Hyderabad
    Jobs in Kolkata
    Jobs in Mumbai
    Jobs in Noida
    Jobs in Pune

    返信削除