At a terminal prompt:
heroku login -i
You will see something like:
heroku: Enter your login credentials
Email:
Enter your Heroku email and password1:
heroku: Enter your login credentials
demostudent10@firstdraft.com
Password: ***************
Logged in as demostudent10@firstdraft.com
At a terminal prompt,
heroku create
This will assign a random name to your app. If you want to, you can also choose a name for the app when creating it:
heroku create my-cool-app
Or, at any time, you can rename the app:
heroku rename my-awesome-app
We need to select the Heroku 20 stack for the versions of Ruby/Rails we’re using:
heroku stack:set heroku-20
Make a git commit with your latest work that you wish to deploy. You can use the web interface at /git
, or you can run the following commands at a terminal prompt:
git add -A
git commit -m "Describe your changes"
At a terminal prompt,
git push heroku HEAD:main -f
https://my-awesome-app.herokuapp.com
(or whatever name you chose or were assigned).If you need to set any environment variables on Heroku to mirror the ones you have locally (to e.g. store credentials securely), you can do it in the application’s settings in your Heroku dashboard. (Heroku refers to environment variables as “Config Vars”.)
Then, at a terminal prompt:
heroku domains:add www.your-domain.com
You will see some instructions:
heroku domains:add www.your-domain.com
Adding test.appdevproject.com to ⬢ my-awesome-app... done
Configure your app's DNS provider to point to the DNS Target young-peony-foamxxrzcu9xzxd286waw6ay.herokudns.com.
For help, see https://devcenter.heroku.com/articles/custom-domains
The domain www.your-domain.com has been enqueued for addition
Run heroku domains:wait 'www.your-domain.com' to wait for completion
www
to the target that Heroku gave you (in the example above, young-peony-foamxxrzcu9xzxd286waw6ay.herokudns.com
).When your users run into errors, we don’t want them to see the gory details of what went wrong. So, rather then show them the detailed error messages, we just show them a generic “Something went wrong” page when running the application in production mode.
But then, how will you debug errors that your users will, inevitably, discover in your code? Eventually, you should add a service like Rollbar, which will automatically log every error and send you a detailed report. But for now, you should look at the error message in your server log.
How can you look at your Heroku server log? With this command:
heroku logs --tail
That will show us what’s going over there in California:
You’ll notice that the production server log is not as helpful as the development log! What I do is clear the Terminal with Cmd+K, and then refresh the request that was causing the error. I then scroll to the top of the mess, and start to look through carefully for the error message.
You can run rake tasks on a schedule very easily on Heroku. First,
heroku addons:create scheduler:standard
Then,
heroku addons:open scheduler
It will give you a URL to open, at which you’ll find a dashboard. You can then specify a task (e.g. rails send_sms
or whatever you named your task) and a frequency that you want the task to be run. Your options are every day, every hour, and every 10 minutes. That’s it!
If you have Multi-Factor Authentication enabled, then instead of your password you’ll need to paste an API Key. Generate and copy your API Key under your Account Settings in the Heroku Dashboard: