shou2017.com
JP

All steps to deploy a rails app to heroku

Mon Aug 7, 2017
Sat Aug 10, 2024

We assume that you have already registered as a user of Heroku and so on.

First, make sure Heroku CLI is installed.

$ heroku --version
bash: heroku: command not found

It is not installed, so install it.

You can find instructions on Heroku CLI. The commands may change, so be sure to check the official version.

On a mac, you can use

$ brew install heroku/brew/heroku

For Ubuntu / Debian

$ wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh

For windows, install from Heroku CLI (tough).

Make sure you have installed it.

$ heroku --version
heroku-cli/6.15.5 (linux-x64) node-v9.2.1

Log in

$ heroku login

By the way, if you want to do this with Cloud9, you need to install software to operate heroku.

$ wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh

When you heroku login, you will be asked for your email address and password, so just answer the ones you registered beforehand and you are good to go.

If the login succeeds, your email address will be displayed.

$ heroku login
Enter your Heroku credentials.
Email:[email protected]
Password:Password
Logged in as [email protected]

After successfully logging in. Use heroku create to create an application frame.

$ heroku create
Creating app... done, ⬢ immense-chamber-761
https://sample.herokuapp.com/ <= this is the url

Asset precompilation

Open config/environments/production.rb.

Omit.

config.assets.compile = true <= false to true

Next.

$ rake assets:precompile RAILS_ENV=production

Asset precompile is always done after working on assets, before sending it to heroku.

Display errors in the console

If there is an error in heroku, it will not show up in the console, so install the gem.

gem 'rails_12factor', group: :production

Send to heroku.

$ git add -A
$ git commit -m “test”
$ git push heroku master

Since heroku creates the database automatically, you don’t need to use rake db:create.

$ heroku run rake db:migrate RAILS_ENV=production

Set environment variables.

$ heroku config:add SECRET_TOKEN="$(bundle exec rake secret)

Once you’re done here, all you need to do is access the url you just created.

Commonly used in heroku

Check the logs.

$ heroku logs -t

Send an empty file. You need to change it a bit to send the same content as before.

$ git commit -m “for deploy heroku” --allow-empty

Send from a branch other than master.

$ git push heroku develop:master

The end.

See Also