It will be a personal memorandum. All basic operations are done in the macOS terminal.
Open a terminal and enter the following command.
% brew tap heroku/brew && brew install heroku
When the installation is complete, enter the following command to confirm the completion. Here you should see it in heroku/x.y.z output.
% heroku --version
heroku/7.0.0 (darwin-x64) node-v8.0.0
After installing the CLI, run the heroku login command. You will be asked for your email address and password, so enter them.
% heroku login
=> Enter your Heroku credentials.
#Enter your email address and press enter
=> Email:
#Enter your password and press enter
=> Password:
If Logged in as email address is output, login is successful.
%cd Location of the app you want to deploy
When creating an app, the app name must be unique, so you'll get an error if it's already in use by someone else. Also, since the app name becomes part of the domain, you cannot use character strings that cannot be used in the domain. Pay attention to the above two points and enter the following command.
%heroku create application name
If you want to confirm that the settings are correct, enter the following.
% git config --list | grep heroku
After inputting, if anything other than fatal: not in a git directory is displayed, it is successful.
On Heroku, the database setting used is PostgreSQL by default. To use MySQL, you can use MySQL on Heroku by adding an add-on provided by a database service called ClearDB.
Enter the following command to add the ClearDB add-on.
% heroku addons:add cleardb
If you use Ruby on Rails, you need to consider the gem that supports MySQL, and change that setting. First, enter the following command.
% heroku_cleardb=`heroku config:get CLEARDB_DATABASE_URL`
You have now stored the URL of your ClearDB database in the variable heroku_cleardb. Then enter the following command.
% heroku config:set DATABASE_URL=mysql2${heroku_cleardb:5}
On Heroku, set the value of master.key as an environment variable (one of the data sharing functions provided by the OS, "a variable that can be referenced from any directory file"). First, enter the following command.
% heroku config:set RAILS_MASTER_KEY=`cat config/master.key`
To see the Heroku environment variable list for correct settings, enter the following command:
% heroku config
After inputting, if there is an item RAILS_MASTER_KEY: , it is successful.
You can add application information to Heroku by pushing a commit to Heroku. Enter the following command.
% git push heroku master
The database does not reflect the migration information, so keep heroku run in mind when performing the migration.
% heroku run rails db:migrate
To see the application information reflected in Heroku in the previous steps, enter the following command:
% heroku apps:info
% heroku open
Deployment is complete when the application opens without any problems.
If you run into problems that prevent your app from working properly, check the logs. By adding --tail, only the last 10 lines of the log can be displayed.
% heroku logs --tail --app application name
If there are any differences in the file since you pushed it to Heroku, you can commit as usual and push that commit to Heroku. Execute the following code in order from the top.
% git add .
% git commit -m "Commit name that is easy to understand later"
% git push heroku master
If you don't have any files to change, but you want to reflect only the environment variables set in Heroku in the production environment, the above method will display "Everything up-to-date (already updated to the latest state)". Will be done. So we'll deliberately create an empty commit and push it to Heroku. Execute the following code in order from the top.
% git commit --allow-empty -m "Empty commit"
% git push heroku master
Recommended Posts