LoginSignup
3
5

More than 3 years have passed since last update.

【Heroku】デプロイ手順

Last updated at Posted at 2019-07-21

準備:Herokuログイン

Herokuのサイトに登録して、
ターミナルにてCLIでHerokuにログイン

$ heroku login

準備:Gemfile修正

  • production(Heroku)でsqlite3を利用しないように修正しておく
  • production(Heroku)でpgを利用するように修正しておく
Gemfile
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]
gem 'pg', group: :production

準備:git commit

ソースをコミットしておく

# アプリのディレクトリに移動する
$ cd rails-app

# 初期化
$ git init

# ディレクトリ配下のファイルをコミット対象にする
$ git add *

# コミット
$ git commit -m "Release to heroku"

Herokuアプリ作成

Herokuアプリを作成して、URLとGitリポジトリを取得する

  • <アプリ名>は省略可能。省略するとアプリ名が自動で払い出される
  • 払い出されたURLがHerokuアプリのURL、Gitリポジトリとなる
# アプリのディレクトリに移動する
$ cd rails-app

# Herokuアプリを作成する
$ heroku create <アプリ名>

Creating app... done, ⬢ xxxxx-xxxxx-xxxxx
https://xxxxx-xxxxx-xxxxx.herokuapp.com/ | https://git.heroku.com/xxxxx-xxxxx-xxxxx.git

リモートリポジトリの確認・登録

リモートリポジトリherokuが作成されてることを確認する

# リモートリポジトリを確認
$ git remote
heroku

リモートリポジトリherokuが存在しない場合は、heroku create <アプリ名>コマンド実行時に払い出されたgitリポジトリをリモートリポジトリherokuとして登録する

# リモートリポジトリを追加
$ git remote add heroku https://git.heroku.com/xxxxx-xxxxx-xxxxx.git

補足:ローカルリポジトリ作成(git init)後にheroku createコマンドを実行した場合はリモートリポジトリherokuが自動で追加されますが、 heroku createコマンド実行後にローカルリポジトリを作成(git init)した場合は、手動でリモートリポジトリherokuを追加する必要があります。

デプロイ

ローカルのmasterブランチをリモートリポジトリherokuへpushする

$ git push heroku master

...
To https://git.heroku.com/mighty-beyond-37933.git
 * [new branch]      master -> master

アクセス確認

heroku openコマンドを実行すると自動でブラウザが開き、HerokuアプリのURLにアクセスする

$ heroku open

または、HerokuアプリのURLにブラウザでアクセスする
https://xxxxx-xxxxx-xxxxx.herokuapp.com/

3
5
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
3
5