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