EC2にSSHで接続し、git pullしてからよく使うコマンドまとめました。
- 使用頻度が多いものを自分用に簡単にまとめました。
環境
rails 5.2.4
ruby 2.6.3
Cloud9
MySQL
AWSの構成
EC2にSSHで接続する方法
$ ssh -i ~/.ssh/キー名.pem ec2-user@xx.xx.xx.xx
Nginxの再起動する方法
$ sudo systemctl restart nginx
アプリ(puma)起動する方法
$ rails s -e production
アプリ(puma)停止する方法
$ kill プロセスID
どちらも同じです
$ kill $(cat tmp/pids/puma.pid)
本番環境でbundle installする時のコマンド
$ bundle install --path vendor/bundle --without test development
CSS・JS変更時に使うコマンド
$ bundle exec rails assets:precompile RAILS_ENV=production
本番環境でrails db:migrateする時のコマンド
$ bundle exec rails db:migrate RAILS_ENV=production
seeds.rb編集した場合は、本番環境のデータベースを削除してからやり直す方がいいです。
本番環境のデータはなくなるので使う際はご自身で判断してください。
$ RAILS_ENV=production DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:drop
$ mysql -u root -p -h エンドポイント
mysql> CREATE DATABASE 作成したいデータベース名;
$ bundle exec rails db:migrate RAILS_ENV=production
$ bundle exec rails db:seed RAILS_ENV=production
nginxエラーログ確認するコマンド
$ sudo tail -f /var/log/nginx/error.log
railsのエラーログ確認するコマンド
$ sudo tail -f log/production.log
全体の把握に時間がかかりたくさんのエラーを経験し心が折れそうになりました。
何度もEC2作り直ししましたのでAWSの知識もより深まりました。
今回は、S3を使っていないため今度はS3を使って構成することを考えてます😄