Deploy heroku with Rails6 (Cloud9 + Ubuntu) + MySQL

1 Heroku CLI Download and install

$ sudo curl https://cli-assets.heroku.com/install-ubuntu.sh | sh

$ heroku --version

2 Heroku login

$ cd appname
$ heroku login --interactive
#You will be asked for your email address and password, so enter them and click enter
Enter your Heroku credentials:
Email: [email protected]
Password: *********

3 Then add the key to Heroku.

heroku keys:add

4 Would you like to upload to Heroku? Is asked, so enter y

? Would you like to upload it to Heroku? (Y/n)

#Then, if the following code appears, it is successful.
Uploading /home/ec2-user/.ssh/id_rsa.pub SSH key... done

5 heroku app creation

$ heroku create appname

6 * heroku DB settings Created with ignite plan (free)

$ heroku addons:create cleardb:ignite --app appname

7 * Environment variable settings

$ heroku config 
=== <App name> Config Vars
CLEARDB_DATABASE_URL: mysql://<username>:<password>@<hostname>/<Database name>?reconnect=true

##Rewrite each item and set variables
$ heroku config:add DB_NAME='<Database name>'
$ heroku config:add DB_USERNAME='<username>'
$ heroku config:add DB_PASSWORD='<password>'
$ heroku config:add DB_HOSTNAME='<hostname>'
$ heroku config:add DB_PORT='3306'
$ heroku config:add DATABASE_URL='mysql2://<username>:<password>@<hostname>/<Database name>?reconnect=true'

 ※ ##Do heroku config again and DATABAS_URL、CLEARDB_DATABASE_Check if the URL starts with mysql2

#Apologetic example
CLEARDB_DATABASE_URL:     mysql://b60b5336b9085d:[email protected]/heroku_f69d4fc63e3b43f?reconnect=true
DB_HOSTNAME:              us-cdbr-iron-east-05.cleardb.net
DB_NAME:                  heroku_f69d4fc63e3b43f
DB_PASSWORD:              754f140c
DB_PORT:                  3306
DB_USERNAME:              b60b5336b9085d
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE:          0d58d7c950379d4bfe741b3ae465b46aaa159ae398c2aaaea5010ae2d817b308a90a7d4702e6281ad609c94de1acf03cb50c1e39d21d9e66af636d812f2e823

* Normal example
CLEARDB_DATABASE_URL:     mysql2://b60b5336b9085d:[email protected]/heroku_f69d4fc63e3b43f?reconnect=true
DB_HOSTNAME:              us-cdbr-iron-east-05.cleardb.net
DB_NAME:                  heroku_f69d4fc63e3b43f
DB_PASSWORD:              754f140c
DB_PORT:                  3306
DB_USERNAME:              b60b5336b9085d
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE:          0d58d7c950379d4bfe741b3ae465b46aaa159ae398c2aaaea5010ae2d817b308a90a7d4702e6281ad609c94de1acf03cb50c1e39d21d9e66af636d812f2e823f

8 Modified config / environments / production.rb (addition)

config.assets.compile = true
config.assets.initialize_on_precompile=false

9 Deploy to heroku

$ git init
$ git add -A
$ git commit -m "first"
$ git push heroku master

$ heroku run rake db:migrate
#If you also want to update the seed
$ heroku run rake db:seed

Recommended Posts

Deploy heroku with Rails6 (Cloud9 + Ubuntu) + MySQL
Deploy to heroku with Docker (Rails 6, MySQL)
Rails6 (MySQL, Ubuntu environment, Cloud9)
Rails deploy with Docker
[Rails] Development with MySQL
Error deploying rails5 + Mysql to heroku with Docker-compose
Deploy Line bot with rails5 + Docker + Heroku Note
Rails + MySQL environment construction with Docker
Rails (postgeresql. Ubuntu environment), heroku deployment
[Environment construction with Docker] Rails 6 & MySQL 8
Deploy Rails on Docker to heroku
Deploy your Rails app on Heroku
heroku deploy
Create Rails 6 + MySQL environment with Docker compose
Deploy to Heroku [Ruby on Rails] Beginner
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Deploy Rails to ECS Fargate with AWS Copilot
[Rails MySQL] How to reset DB on heroku
heroku: docker: deploy
I made a LINE bot with Rails + heroku
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (5)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (6)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (3)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (2)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (1)
[Rails AWS Docker] Build an existing Ruby on Rails + MySQL application with Docker and deploy it on AWS (4)
How to make batch processing with Rails + Heroku configuration
[Heroku] Associate AWS S3 with the deployed Rails app
Environment construction of Rails5 + MySQL8.0 + top-level volumes with docker-compose
Build Rails (API) x MySQL x Nuxt.js environment with Docker
[Rails 6] RuntimeError with $ rails s
Rails Heroku deployment procedure
Heroku app moving (rails)
Install Gradle with ubuntu16.04
Handle devise with Rails
[Rails] Learning with Rails tutorial
Deploy RAILS on EC2
rails heroku error log
[Rails] Heroku deployment flow
[Rails] Test with RSpec
[Docker] Connection with MySQL
Supports multilingualization with Rails!
Double polymorphic with Rails
Cloud9 (Rails) from Github
Continuous integration on Alibaba Cloud ECS Ubuntu instance with Jenkins
Created the first LINEbot on AWS Cloud9 (Rails + Heroku deployment)
[rails] heroku deployment error ActionView :: Template :: Error (Mysql2 :: Error: Table --- doesn't exist):
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]