LoginSignup
2

More than 3 years have passed since last update.

[Rails]herokuへのアプリ公開手順メモ

Posted at

対象者

プログラミング初学者、Ruby on Rails初学者。
こちらの記事は
・初学者の自分の知識整理
・同じような初学者向けにわかりやすく解説する
ことを目的としております。

herokuとは

herokuとはPaaS(Platform as a service)の一つです。
通常サービスを本番環境にアップする為には
サーバ、OS、実行環境などが必要ですがそれらを簡単に提供してくれるのがPaaSです。
ユーザーはアプリケーションを乗せるだけでインターネット上に
サービスを公開することができます。

前提条件

・公開するRailsアプリを準備している
・Railsアプリはローカル環境で問題なく動いている
・herokuアカウントを作成済み

手順

heroku CLIをインストール

https://devcenter.heroku.com/articles/heroku-cli
こちらからheroku CLI(command line interface)をインストールしましょう。
これでターミナルでherokuコマンドが使用できるようになります。

herokuへログイン

herokuにログインします。CUIでそのまま入力したいので-iをつけています。

$ heroku login -i
Email: yourEmail
Password: *******

heroku側でのアプリ作成

githubにレポジトリを作るようなイメージ

$ heroku create app_name
https://app_name.herokuapp.com/ | https://git.heroku.com/app_name.git

app_nameは省略すれば自動的にuniqueな名前が割り当てられます。
この時点でherokuという名前でremoteレポジトリに登録されているので
git remote -vで確認しておきましょう。
登録されてない場合は

$ git remote add heroku https~~

としてremoteに追加します。

herokuへプッシュ

$ git push hreoku master

masterブランチをherokuへpushします。

※ここでDBがRails初期のsqlite3のままだとエラーが出ますので
postgreSQLかMySQLへ変更しましょう。

db:migrate

ローカル環境と同じようにdb:migrateをしましょう

$ heroku run rails db:migrate

まとめ

sqlite3がrails内部で起動されるので便利なのですが
一方でherokuに対応していません。
その為Rails Tutorialさんの手順にあるように
test, development環境ではsqlite3
production環境ではpostgresql
を使うのが最適なのかな、と思っています。

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