LoginSignup
4
5

More than 5 years have passed since last update.

herokuでRailsとMySQLの組み合わせで動かす

Posted at

heroku toolbeltのインストール

https://toolbelt.heroku.com/
herokuコマンドが使用できるようになる。

CentOSの場合

CentOSの場合、以下でインストール可能。

~ wget --no-check-certificate https://toolbelt.heroku.com/install.sh
~ sudo sh ./install.sh
~ echo 'PATH="/usr/local/heroku/bin:$PATH"' >> ~/.zshrc
~ source ~/.zshrc

~ heroku --version
heroku-toolbelt/3.10.5 (x86_64-linux) ruby/2.1.0

herokuでアプリケーションの作成を行う

~ heroku create app_name

既存リポジトリをherokuに登録

作成したアプリケーションのgitリポジトリを見て、以下は書き換える。

~ heroku git:remote -a app_name

~/.ssh/configの設定

herokuに接続するためにはconfigの指定が必須です。

~ vim ~/.ssh/config
Host heroku.com
    User username
    port 22
    Hostname heroku.com
    IdentityFile ~/.ssh/heroku_id_rsa
    TCPKeepAlive yes
    IdentitiesOnly yes
~ chmod 600 ~/.ssh/config

herokuへのデプロイ

以下のコマンドでデプロイ

~ git push heroku current_branch:master

MySQLの設定

初期設定

add-onによりClearDBを追加。後に以下のコマンドにて接続情報を確認。

~ heroku config --app applicationID
CLEARDB_DATABASE_URL:        mysql://xxxxxxxxxxxxxxxxxxx@us-cdbr-iron-east-01.cleardb.net/heroku_xxxxxxxxxxxxxxxxxxx?reconnect=true

この情報をもとにherokuの環境変数を変更します。

~ heroku config:set DATABASE_URL='mysql2://xxxxxxxxxxxxxxxxxxx@us-cdbr-iron-east-01.cleardb.net/heroku_xxxxxxxxxxxxxxxxxxx?reconnect=true'

Migration実行

~ heroku run rake db:migrate

ドメインの設定

herokuにドメインの登録

Custom Domains
こちらを参考に。

~ heroku domains:add hoge.com
~ heroku domains:add www.hoge.com

AWS Route53 + S3を使用したドメインの設定

herokuで独自ドメインをRoute53で設定する
こちらをそのまま参考に。

以下は公式ドキュメント
Configuring Amazon Route 53 DNS for your Heroku App

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