2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Herokuでのデプロイ方法【Rails/mysql】

Last updated at Posted at 2020-05-10

個人アプリをHerokuでデプロイ実施
とても簡単でしたので備忘録を兼ねてまとめていきます。

HEROKUに会員登録

HEROKUとgitを紐付けましょう

https://www.heroku.com/
↑サイトからDLするか、下記コマンドをターミナルに打ち込みます

ターミナル
$ brew tap heroku/brew && brew install heroku

ブラウザが立ち上がりログインをします

$ heroku login

SSHキーの作成

$ heroku keys:add ~/.ssh/id_rsa.pub

作成したSSHキーの確認

$ heroku keys

デプロイしたいアプリのディレクトリに移動しHEROKUを作成

$ cd ~/myapp 
$ heroku apps:create <アプリの名前> (URL名になります)

リモートリポジトリの確認
アプリ名の変更修正

$ git remote -v
$ heroku git:remote -a <変更後のアプリの名前>

HEROKUのDB設定

igniteプラン(無料)で作成

$ heroku addons:create cleardb:ignite

※クレジットカード登録が必要

▸    Please verify your account to install this add-on plan (please enter a credit card) For more
▸    information, see https://devcenter.heroku.com/categories/billing Verify now at
▸    https://heroku.com/verify

環境変数の設定

ClearDBのURL確認

$ heroku config
=== <アプリの名前> Config Vars
CLEARDB_DATABASE_URL: mysql://<ユーザー名>:<パスワード>@<ホスト名>/<データベース名>?reconnect=true

各項目を書き換えて変数を設定

$ heroku config:add DB_NAME='<データベース名>'
$ heroku config:add DB_USERNAME='<ユーザー名>'
$ heroku config:add DB_PASSWORD='<パスワード>'
$ heroku config:add DB_HOSTNAME='<ホスト名>'
$ heroku config:add DB_PORT='3306'
$ heroku config:add DATABASE_URL='mysql2://<ユーザー名>:<パスワード>@<ホスト名>/<データベース名>?reconnect=true'

・config/environments/production.rbを修正(追記)

config.assets.compile = true
config.assets.initialize_on_precompile=false

HEROKUへデプロイ

ローカルリポジトリをHEROKUへプッシュ

$ git push heroku master

マイグレーションを実行

$ heroku rake db:migrate

無事エラーがなければ下記コマンドでURLを開く

$ heroku open
2
1
1

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?