[RUBY] How to deploy on heroku

【Overview】

1. Procedure </ b>

2. Method </ b>

  1. Procedure

❶brew tap heroku/brew && brew install heroku ❷gem 'rails_12factor' ❸ Creating a file for heroku ❹ Creating a DB for heroku ❺ Setting environment variables ❻ Push to master on heroku ❼ Implementation of migration on heroku


2. Method

❶brew tap heroku/brew && brew install heroku

Terminal


% brew tap heroku/brew && brew install heroku

Let's run! We recommend that you do it with the corresponding file of the app you want to publish to heroku so as not to make a mistake! And% heroku login --interactive Log in to heroku with!

❷gem 'rails_12factor'

gemfile


group :production do
  gem 'rails_12factor'
end

And do% bundle install! And commit to master.

❸ Creating a file for heroku

Terminal


% heroku create *****

Create the name of the app you want to publish to heroku with.

❹ Creating a DB for heroku

Terminal


% heroku addons:add cleardb

And create a database.

Terminal


% heroku config | grep CLEARDB_DATABASE_URL

This will bring up CLEARDB_DATABASE_URL, so if you are using mysql2 depending on your usage, change it.

> How to change <

Terminal


% heroku config:set DATABASE_URL = 'mysql2:*****'

For the **** part, copy the one from% heroku config | grep CLEARDB_DATABASE_URL.

❺ Setting environment variables

Terminal


% heroku config:set RAILS_MASTER_KEY=`cat config/master.key`

This will allow you to visit the site without writing the password in the file and hiding it.

❻ Push to master on heroku

Terminal


% git push heroku master

You can push to heroku here.

❼ Implementation of migration on heroku

Terminal


% heroku run rails db:migrate

Since I made a DB with ❹, I will migrate it on heroku as well as local.

You can now publish your app to heroku. However, please note that since no password has been set, anyone can look into the site. Environment variables are just to prevent your site from being hijacked.

Recommended Posts