LoginSignup
0
0

More than 1 year has passed since last update.

EC2 rails 環境構築

Posted at
$ sudo yum -y update
$ sudo yum  -y install git make gcc-c++ patch libyaml-devel libffi-devel libicu-devel zlib-devel readline-devel libxml2-devel libxslt-devel ImageMagick ImageMagick-devel openssl-devel libcurl libcurl-devel curl
$ sudo curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -
$ sudo yum -y install nodejs
$ sudo yum -y install wget
$ sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
$ sudo yum -y install yarn
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source .bash_profile
$ git clone (httpから始まるやつ)
$ rbenv rehash
$ rbenv install (gitのバージョンに合わせる)
$ rbenv global (バージョン)
$ rbenv rehash
$ ruby -v
$ sudo yum -y install mysql56-server mysql56-devel mysql56 mariadb-server mysql-devel
$ sudo yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
$ sudo yum-config-manager –enable mysql80-community
$ sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
$ sudo yum install mysql-community-server
$ mysqld --version
$ mysql -u admin-p -P 3306 -h (RDSのエンドポイント)

※セキュリティーグループのインバウンドルール追加、


sudo mkdir -p /var/www
cd /var/www/
sudo chmod 755 www
cd www/
sudo git clone (ギットハブのhttpsを貼り付け)
cd (作成したフォルダー)
gem install bundler
touch .gemrc
vim .gemrc (なんか貼り付け)
gem install rails -v 6.1.4
cd /var/www/jojorion
bundle install
www $sudo chown ec2-user:ec2-user jojorion/
cd jojorion
$sudo chown -R ec2-user:ec2-user .
bundle install

vim config/database.yml (編集・追加)
bundle exec rails webpaker:install no! no!コマンド
RAILS_ENV=production bundle exec rails db:create
EDITOR=vim bin/rails credentials:edit
cat config/master.key (ローカルから鍵を取ってきてEC2に貼り付ける) 
RAILS_ENV=production bundle exec rails db:create
RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production bundle exec rails s -b 0.0.0.0
動作確認する

___ 

 sudo=ルート権限
/www配下にアプリケーション用のディレクトリーを入れる。
sudo chmod 755 /var/www/
※www/以降を755権限にする
sudo chown -R <ユーザー名>:<ユーザー名>
sudo chown -R ec2-user:ec2-user /var/www  
※オーナー所持者

↓bundle installがうまくいかない場合は、下記コマンドを実行する↓
$ bundle install --path vendor/bundle

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0