Rails Heroku deployment procedure

Please point out any corrections for beginners in programming. It is assumed that you have git installed.

Own environment

Deployment flow

  1. Setting up The Heroku CLI
  2. Log in to Heroku
  3. Deploy to Heroku

What is Heroku

Heroku is a cloud platform that makes it easy to publish web applications to the world.

Reference) What is HEROKU?

Register as a Heroku user from the URL below. User registration is free.

https://signup.heroku.com/jp

1. Setting up The Heroku CLI

By installing The Heroku CLI, you can use Heroku commands.

Please specify the OS from the link below and download it to complete the installation.

https://devcenter.heroku.com/articles/heroku-cli

2. Log in to Heroku

Now that you have the Heroku CLI installed, you can use Heroku commands on your terminal.

Let's log in to Heroku from the terminal immediately.

Go to the directory of the app you want to upload to Heroku and run the "heroku login command".

After executing the login command, you will need to enter the email address and password you registered with heroku.

Terminal Make the $ cd app # app part the name of the app you created $ heroku login #Log in to heroku Enter your Heroku credentials: Email:

When you have entered your e-mail address and password, the following will be displayed.


Logged in as the email address you entered


# 3.Deploy to Heroku
Heroku uses a PostgreSQL database.

So, I will install PostgreSQL.

Execute the following command in the terminal. (If you have already installed it, you do not need to install it.)

$ brew install postgresql

Once the installation is complete, production(production)Install pg gem in your environment to allow Rails to communicate with PostgreSQL.

Add the following code to the bottom of the Gemfile.


#### **`Gemfile.`**

group :production do gem 'pg' end


The pg gem is a production gem and should not be installed locally. In that case, bundle install--Add without production. By adding this flag, the pg gem will not be reflected in the local environment. Now execute the following command.

$ bundle install --without production

For production environment of bundle install

Then use the "heroku create app name" command to create an application on heroku. Execute the following command.

$ heroku create

If you do not enter the application name as described above, it will be named automatically.
***Please note that the name once registered cannot be used.***

When I run the above command, I get the following result:

Creating app ... done, ⬢ app (app name) https://app (app name) .herokuapp.com / | https://git.heroku.com/app (app name) .git


https://~~.herokuapp.com/Is the subdomain created by the above command. You can see it in your browser at this point, but there is nothing yet. Let's deploy and display the web page.

To deploy your Rails application to Heroku, first use Git to push the repository to Heroku.

$ git add . $ git commit -m "initial commit" $ git push heroku master


If it goes well, remote as below: Verifying deploy... done.It will be displayed.

. . . remote: Verifying deploy... done. To https://git.heroku.com/app (app name) .git


Next, execute migration with the following command. Rails db that was done in the local environment:The image is that the migrate command is also executed in the production environment.

$ heroku run rails db:migrate


After executing the above command, execute the following command to display the web page.

$ heroku open


that's all.

###Reference article
https://qiita.com/kazukimatsumoto/items/a0daa7281a3948701c39
https://qiita.com/NaokiIshimura/items/eee473675d624a17310f


Recommended Posts

Rails Heroku deployment procedure
[Rails] Heroku deployment flow
Rails (postgeresql. Ubuntu environment), heroku deployment
[EC2 / Vue / Rails] EC2 deployment procedure for Vue + Rails
[Rails / Heroku] Error resolution procedure after push
[rails] gem'payjp' implementation procedure
Heroku app moving (rails)
rails heroku error log
Rails, RSpec installation procedure
Created the first LINEbot on AWS Cloud9 (Rails + Heroku deployment)
[rails] heroku deployment error ActionView :: Template :: Error (Mysql2 :: Error: Table --- doesn't exist):
Launch Rails on EC2 (manual deployment)
rails AWS deployment is not reflected
Rails on Docker environment construction procedure
Deploy Rails on Docker to heroku
[Rails] Comment function implementation procedure memo
App update reflected after heroku deployment
[Rails] AWS deployment error encounter summary
Deploy your Rails app on Heroku
How to redo a deployment on Heroku
Easy deployment with Capistrano + AWS (EC2) + Rails
Deploy heroku with Rails6 (Cloud9 + Ubuntu) + MySQL
Deploy to heroku with Docker (Rails 6, MySQL)
Deploy to Heroku [Ruby on Rails] Beginner
Rails Basic CRUD function implementation procedure scaffold
[heroku] run rails db: migrate doesn't work
[heroku deployment procedure ③] From Ruby version specification to deployment and access to the application (complete)