amazon linux2 に apache 入れて rails

aws

o yum -y install httpd

$ httpd -v
Server version: Apache/2.4.41 ()

起動
$ sudo systemctl start httpd.service

自動起動ON
$ sudo systemctl enable httpd.service

確認
$ systemctl is-enabled httpd.service

ruby2.7にしましょう(下記記事参照)
https://blog.office-aship.info/amazon-linux2-rbenv-ruby-2-7/

$ gem install passenger -N
Successfully installed passenger-6.0.4

$ sudo chmod o+x “/home/ec2-user”
$ sudo yum -y install gcc-c++
$ sudo yum -y install libcurl-devel
$ sudo yum -y install httpd-devel
$ sudo yum -y install apr-devel
$ sudo yum -y install apr-util-devel

$ passenger-install-apache2-module

$ sudo vi /etc/httpd/conf/httpd.conf

以下を末尾に
LoadModule passenger_module /home/ec2-user/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/passenger-6.0.4/buildout/apache2/mod_passenger.so

PassengerRoot /home/ec2-user/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/passenger-6.0.4
PassengerDefaultRuby /home/ec2-user/.rbenv/versions/2.7.0/bin/ruby

Passengerを組み込んだApacheではDocumentRootを$RAILS_ROOT/publicに設定すれば、自動的にRailsアプリケーションが認識されます。

以下のように修正(DocumentRootはあなたの環境に合わせて)
#DocumentRoot “/var/www/html”
DocumentRoot “/home/ec2-user/rails_app/public”


Options Indexes FollowSymLinks
AllowOverride None
Require all granted

$ bundle
$ bundle exec rails assets:precompile RAILS_ENV=production

database.yml と .env 設定

apache restart
$ sudo systemctl restart httpd.service

タイトルとURLをコピーしました