AWSRails apach + passenger 環境 忘備録
passengerのモジュールをインストール
496 sudo yum install lobcurl-devel 497 sudo yum install httpd-devel 498 sudo yum install apr-devel 499 sudo yum install apr-util-devel
rbenvだと rehash しないとgemが反映されない 大切
これらすべての問題は,railsのbundlerにgemを追加したことが原因と推定 理由 グローバルにpassenger の gemが入っていないため、/home以下フォルダにて でアパッチのビルドができない。
sudo passenger-install-apache2-module
これはrubyのgemがapachを動かすmodule
ここが非常に参考になる
Apache上でRuby on Railsアプリケーションを動かす/Passenger(mod_rails for Apache)の利用 — Redmine.JP
再度ログインするとyumをupdateしろと
以下のパッケージが新たにインストールされた。
Installing: kernel x86_64 4.14.97-74.72.amzn1 amzn-updates 21 M kernel-devel x86_64 4.14.97-74.72.amzn1 amzn-updates 14 M Updating: curl x86_64 7.61.1-7.91.amzn1 amzn-updates 362 k kernel-headers x86_64 4.14.97-74.72.amzn1 amzn-updates 1.2 M kernel-tools x86_64 4.14.97-74.72.amzn1 amzn-updates 127 k libcurl x86_64 7.61.1-7.91.amzn1
bundle install $ rbenv rehash
/home/hogehoge-user
$ gem install passenger Building native extensions. This could take a while... Successfully installed passenger-6.0.1 Parsing documentation for passenger-6.0.1 Installing ri documentation for passenger-6.0.1 Done installing documentation for passenger after 51 seconds 1 gem installed
再度試みる
$ cd /home/ec2-user/ $ passenger-install-apache2-module
するとメモリが足りないという
Your system does not have a lot of virtual memory Compiling Phusion Passenger works best when you have at least 1024 MB of virtual memory. However your system only has 985 MB of total virtual memory (985 MB RAM, 0 MB swap). It is recommended that you temporarily add more swap space before proceeding. You can do it as follows: sudo dd if=/dev/zero of=/swap bs=1M count=1024 sudo mkswap /swap sudo swapon /swap See also https://wiki.archlinux.org/index.php/Swap for more information about the swap file on Linux. If you cannot activate a swap file (e.g. because you're on OpenVZ, or if you don't have root privileges) then you should install Phusion Passenger through DEB/RPM packages. For more information, please refer to our installation documentation: ttps://www.phusionpassenger.com/library/install/apache/ Press Ctrl-C to abort this installer (recommended).
スワップメモリ領域を変更する。
sudo dd if=/dev/zero of=/swap bs=1M count=2048 //512の単位、ここは思い切って2048にした。 sudo mkswap /swap sudo swapon /swap
今度はうまく行った。
これをapachに設定してくださいと
LoadModule passenger_module /home/ec2-user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/passenger-6.0.1/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /home/ec2-user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/passenger-6.0.1 PassengerDefaultRuby /home/ec2-user/.rbenv/versions/2.4.1/bin/ruby </IfModule>
詳細はこのサイトをみてねと言われる。
Deploying an application - Apache - Passenger Library
以下を実行
これはpassengerが使うrubyとrailsが使うrubyが同じかどうかチェックするコマンド
passenger-config about ruby-command
rubyが使うのもapachが使うのも同じ 問題ない
$ passenger-config about ruby-command passenger-config was invoked through the following Ruby interpreter: Command: /home/ec2-user/.rbenv/versions/2.4.1/bin/ruby Version: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] To use in Apache: PassengerRuby /home/ec2-user/.rbenv/versions/2.4.1/bin/ruby To use in Nginx : passenger_ruby /home/ec2-user/.rbenv/versions/2.4.1/bin/ruby To use with Standalone: /home/ec2-user/.rbenv/versions/2.4.1/bin/ruby /home/ec2-user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/passenger-6.0.1/bin/passenger start
アパッチ設定ファイル
$ sudo vi /etc/httpd/conf/httpd.conf
設定内容
<VirtualHost *:80> ServerAdmin localhost DocumentRoot /var/www/html/hogehoge PassengerRuby /home/ec2-user/.rbenv/versions/2.4.1/bin/ruby <Directory /var/www/html/hogehoge/public> Allow from all Options -MultiViews </Directroy> </VirtualHost>
アパッチの再起動
$ sudo service httpd restart