SlideShare a Scribd company logo
HEROKU TIPS AND HACKS
1. Create an account on Heroku.
- Go to website: ​http://heroku.com/
2. Install Heroku toolbelt:​(​https://toolbelt.heroku.com/​)
- It is everything you need to get started using Heroku.
- Install: ​wget -qO- ​https://toolbelt.heroku.com/install-ubuntu.sh​| sh
3. Login to Heroku
- Run: $ heroku login (enter username and password)
- If have errors about ssh key:
http://www.ajibanda.com/2013/02/reset-git-ssh-key-to-log-in-using-a-new-heroku-
account.html
4. Add gem and config asset pipeline :
- In Gemfile:
gem ‘rails_12factor’, group:production
gem ‘thin’
- In config/application.rb:
config.assets.initialize_on_precompile = false
* Remember: Must commit ​Gemfile.lock ​to server to deploy.
* More details: ​https://devcenter.heroku.com/articles/getting-started-with-rails3
5. CLI Heroku: ​$ heroku run <...>
$ heroku run rake db:migrate
$ heroku restart <name_app_heroku>
$heroku open (open website in browser)
$ heroku run rails c
$ heroku run ruby script/imap_processor start
- Dùng cmd: $ heroku run bash
- View list current account: $ heroku accounts
6. Push local project to Heroku
- Git init in local project:
$ git init
- Add host to current git:
$ git remote add <​origin​> <git@heroku/app>
(​git@heroku.com​:bookmanageapp.git)
- Check remote exist or not? :
$ git remote -v
- Add and commit code
- Push code - ​Deploy code
$ git push [hostname] [branch] / $ git push ​origin/heroku​master
7. Cloning Existing Heroku Applications
$ heroku login
$ heroku git:clone -a <my_app>
$ cd my_app
* More details: ​https://devcenter.heroku.com/articles/git-clone-heroku-app
8. Delayed Job
* More details: ​https://devcenter.heroku.com/articles/delayed-job
9. View processes - logs
- View processes:
$ heroku ps
=== delayed (1X): `bundle exec rake jobs:work`
delayed.1: up 2013/11/04 19:38:01 (~ 15h ago)
=== web (1X): `bundle exec thin start -R config.ru -e $RAILS_ENV -p $PORT`
web.1: up 2013/11/05 08:12:55 (~ 2h ago)
- View logs:
$ heroku logs / $ heroku logs --tail
$ heroku logs -p imap.1
$ heroku logs -p web.
- View db info:
$ heroku config
* More details: ​https://devcenter.heroku.com/articles/logging
10. Multi accounts:
- Add account:
$ heroku accounts:add <name> -- auto
- Remove account:
$ heroku accounts:remove <name>
- Using account:
$ heroku accounts:set <name>
* Remember: Config (host) in: ~/.ssh/config
* More details: ​https://github.com/ddollar/heroku-accounts
- Add key: $ heroku keys:add
- Ex: Found the following SSH public keys:
1) id_rsa.pub
2) identity.heroku.app_rails.pub
3) identity.heroku.personal.pub
4) identity.heroku.work.pub
5) ssh-add id_rsa.pub
Which would you like to use with your Heroku account? => ​3
*More details: ​https://devcenter.heroku.com/articles/keys
11. Config timeout:
https://github.com/heroku/rack-timeout
http://www.rubydoc.info/gems/rack-timeout/0.0.4/frames
12. Access to db postgres on Heroku
- Click to Heroku Postgres Dev on website Heroku application.
- In this page, content some info:
Host : host_path (ec2-123-321-333.compute-00.compute-1.amazonaws.com)
Database: db_name_pg
User: user_name
Password: password
- Connect to database:
$ psql -U <username> -h <host> -d <database>
$ psql -U user_name -h host_path -d db_name_pg
13. View Memory (RAM), CPU, Core based on dyno sizes:
Dyno 
Size 
Memory 
(RAM) 
CPU 
Share 
Multitenan
t 
Compute 
(​2​) 
Price/dyno­hou
r 
1X  512MB  1x  yes  1x­4x  $0.05 
2X  1024MB  2x  yes  4x­8x  $0.10 
PX  6GB  100% (1)  no  40x 
$0.80 
 
*More details:​https://devcenter.heroku.com/articles/dyno-size#available-dyno-sizes
14. Config Domain:
- Add domain:
$ heroku domain add: <example.com>
or add in ​Setting ​section on heroku website.
- Get domain default on heroku: http://<my_app>.heroku.com
Ex: ​http://my_app.herokuapp.com
- Get IP of above domain:
$ host ​my_app.herokuapp.com
=> my_app.herokuapp.com has address ​23.23.80.206
- Go to Godaddy or others service, config your domain point to this IP.
More details: ​https://devcenter.heroku.com/articles/custom-domains
15. Upgrade Mongolab ​(From sandbox-free to Single Node SM)
Changing to or from a single-node plan on Heroku:
1. Stop your app and any other processes writing to your database
2. Backup your database using mongodump
3. Remove your existing add-on
4. Add a new add-on (see available plans ​here​)
5. Restore your database using mongorestore
6. Change your connection string info in your app
7. Restart your app
Example:
$ ​mongodump ​-h ds0123456.mongolab.com:3000 -d heroku_app -u user -p password -o .
$ heroku addons:remove mongolab
$ heroku addons:add mongolab:shared-single-small
$ ​mongorestore​-h <new_host>:<new_port> -d heroku_app -u user -p <​new_password​> .
* Get ​<​new_password​>:
Run :
$ ​heroku config | grep MONGOLAB_URI
Output:
mongodb://heroku_app:​new_password​@​ds0123456​.mongolab.com:3000/heroku_app
Compare with:
​mongodb://<dbuser>:<​dbpassword​>@​ds0123456​.mongolab.com:3000/<dbname>
Informations account :
dbuser: ​dbpassword
dbpassword: ​new_password
dbname: ​heroku_app
* More details: ​https://devcenter.heroku.com/articles/mongolab
16. Improve performance with Unicorn (Concurrency)
-​​Add Gem:
gem ‘unicorn’
- Config:
Create a file configuration for Unicorn at config/unicorn.rb
- When using mongoid:
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 30
preload_app true
before_fork do |server, worker|
puts worker
end
after_fork do |server, worker|
puts worker
end
If using Mongoid, you don't need to manually reconnect as in the gist. Mongoid claims:
"When using Unicorn or Passenger, each time a child process is forked when using
app preloading or smart spawning, Mongoid will automatically reconnect to the
master database. If you are doing this in your application manually you may remove
your code." (​http://mongoid.org/en/mongoid/docs/rails.html​)
* More details:​​https://devcenter.heroku.com/articles/rails-unicorn
Other references:
http://railsapps.github.io/rails-heroku-tutorial.html
https://devcenter.heroku.com/articles/getting-started-with-rails3
* Developer: ​Nguyễn Thành Luân

More Related Content

PDF
Хокку про Heroku
PDF
mapserver_install_linux
PDF
Alfredo-PUMEX
PDF
Developing apps using Perl
PDF
Inside Bokete: Web Application with Mojolicious and others
PDF
RESTful web services
PDF
PerlでWeb API入門
PDF
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
Хокку про Heroku
mapserver_install_linux
Alfredo-PUMEX
Developing apps using Perl
Inside Bokete: Web Application with Mojolicious and others
RESTful web services
PerlでWeb API入門
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm

What's hot (20)

PDF
Mojolicious. Веб в коробке!
PDF
PDF
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
PDF
Perl web frameworks
PDF
MeaNstack on Docker
PDF
Mojolicious
KEY
Mojo as a_client
KEY
Devsumi2012 攻めの運用の極意
PPTX
How to create a secured multi tenancy for clustered ML with JupyterHub
PPTX
How to go the extra mile on monitoring
PDF
Hacking ansible
PPTX
Installing odoo v8 from github
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
PDF
PuppetCamp SEA 1 - Version Control with Puppet
PDF
Using docker for data science - part 2
PDF
Ansibleではじめるサーバー・ネットワークの自動化(2019/02版)
PDF
Django osc2018-okinawa
PPTX
How to Install Odoo 11 on Ubuntu 16.04?
PPTX
Webrtc mojo
KEY
Phpne august-2012-symfony-components-friends
Mojolicious. Веб в коробке!
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Perl web frameworks
MeaNstack on Docker
Mojolicious
Mojo as a_client
Devsumi2012 攻めの運用の極意
How to create a secured multi tenancy for clustered ML with JupyterHub
How to go the extra mile on monitoring
Hacking ansible
Installing odoo v8 from github
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
PuppetCamp SEA 1 - Version Control with Puppet
Using docker for data science - part 2
Ansibleではじめるサーバー・ネットワークの自動化(2019/02版)
Django osc2018-okinawa
How to Install Odoo 11 on Ubuntu 16.04?
Webrtc mojo
Phpne august-2012-symfony-components-friends

Viewers also liked (17)

DOCX
Taking care of your voice
DOCX
Tugas spesalite obat
PDF
Bootstrap Tutorial
PDF
Hsp bm sk_y1a
PPTX
11108119李芳靜
PDF
Hsp bm sk_y1d
PPTX
Development banking of mexico
PPTX
COMU2002: Google+
PPTX
COMU3222 (Part 1)
PPTX
COMU3222 (Part 2)
PDF
Facebook
PDF
Conflitti tra studenti: Come affrontarli con la Comunicazione NonViolenta
PPTX
Slausen Presentation
PPTX
COMU1000 Text Analysis
PPTX
Perfeccionamiento museo andino valle del maipo
PPTX
Gala 8°b 2014
PPTX
Euthanasia and Religion in the Media
Taking care of your voice
Tugas spesalite obat
Bootstrap Tutorial
Hsp bm sk_y1a
11108119李芳靜
Hsp bm sk_y1d
Development banking of mexico
COMU2002: Google+
COMU3222 (Part 1)
COMU3222 (Part 2)
Facebook
Conflitti tra studenti: Come affrontarli con la Comunicazione NonViolenta
Slausen Presentation
COMU1000 Text Analysis
Perfeccionamiento museo andino valle del maipo
Gala 8°b 2014
Euthanasia and Religion in the Media

Similar to Heroku Tips and Hacks (20)

PPTX
Introduction to Heroku
PDF
Heroku and Rails Applications
PDF
Heroku 101 py con 2015 - David Gouldin
PDF
Хокку про Heroku
PPTX
Deploying your app.pptx
PDF
How to Upgrade Your Database Plan on Heroku and Rails Setup?
PDF
A Scalable Rails App Deployed in 60 Seconds
ODP
KEY
Heroku + Jeweler & Gemcutter
PPTX
GIT, RVM, FIRST HEROKU APP
PPTX
Getting Started with Heroku
PPTX
2012 coscup - Build your PHP application on Heroku
PDF
Heroku webcastdeck+20130828
KEY
Sinatra and Heroku - A comfortable ruby way for web service
PPTX
Heroku
KEY
PDF
Symfony Deployments on Heroku
PDF
Heroku
PPTX
Architect Track Heroku - A Polyglot Platform [Architecture & Add-ons]By Ashis...
PPTX
Heroku - A ployglot Platform (Add-on)
Introduction to Heroku
Heroku and Rails Applications
Heroku 101 py con 2015 - David Gouldin
Хокку про Heroku
Deploying your app.pptx
How to Upgrade Your Database Plan on Heroku and Rails Setup?
A Scalable Rails App Deployed in 60 Seconds
Heroku + Jeweler & Gemcutter
GIT, RVM, FIRST HEROKU APP
Getting Started with Heroku
2012 coscup - Build your PHP application on Heroku
Heroku webcastdeck+20130828
Sinatra and Heroku - A comfortable ruby way for web service
Heroku
Symfony Deployments on Heroku
Heroku
Architect Track Heroku - A Polyglot Platform [Architecture & Add-ons]By Ashis...
Heroku - A ployglot Platform (Add-on)

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
DOCX
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Digital-Transformation-Roadmap-for-Companies.pptx
Spectral efficient network and resource selection model in 5G networks
The AUB Centre for AI in Media Proposal.docx

Heroku Tips and Hacks

  • 1. HEROKU TIPS AND HACKS 1. Create an account on Heroku. - Go to website: ​http://heroku.com/ 2. Install Heroku toolbelt:​(​https://toolbelt.heroku.com/​) - It is everything you need to get started using Heroku. - Install: ​wget -qO- ​https://toolbelt.heroku.com/install-ubuntu.sh​| sh 3. Login to Heroku - Run: $ heroku login (enter username and password) - If have errors about ssh key: http://www.ajibanda.com/2013/02/reset-git-ssh-key-to-log-in-using-a-new-heroku- account.html 4. Add gem and config asset pipeline : - In Gemfile: gem ‘rails_12factor’, group:production gem ‘thin’ - In config/application.rb: config.assets.initialize_on_precompile = false * Remember: Must commit ​Gemfile.lock ​to server to deploy. * More details: ​https://devcenter.heroku.com/articles/getting-started-with-rails3 5. CLI Heroku: ​$ heroku run <...> $ heroku run rake db:migrate $ heroku restart <name_app_heroku> $heroku open (open website in browser) $ heroku run rails c $ heroku run ruby script/imap_processor start
  • 2. - Dùng cmd: $ heroku run bash - View list current account: $ heroku accounts 6. Push local project to Heroku - Git init in local project: $ git init - Add host to current git: $ git remote add <​origin​> <git@heroku/app> (​git@heroku.com​:bookmanageapp.git) - Check remote exist or not? : $ git remote -v - Add and commit code - Push code - ​Deploy code $ git push [hostname] [branch] / $ git push ​origin/heroku​master 7. Cloning Existing Heroku Applications $ heroku login $ heroku git:clone -a <my_app> $ cd my_app * More details: ​https://devcenter.heroku.com/articles/git-clone-heroku-app 8. Delayed Job * More details: ​https://devcenter.heroku.com/articles/delayed-job 9. View processes - logs - View processes: $ heroku ps === delayed (1X): `bundle exec rake jobs:work` delayed.1: up 2013/11/04 19:38:01 (~ 15h ago) === web (1X): `bundle exec thin start -R config.ru -e $RAILS_ENV -p $PORT` web.1: up 2013/11/05 08:12:55 (~ 2h ago)
  • 3. - View logs: $ heroku logs / $ heroku logs --tail $ heroku logs -p imap.1 $ heroku logs -p web. - View db info: $ heroku config * More details: ​https://devcenter.heroku.com/articles/logging 10. Multi accounts: - Add account: $ heroku accounts:add <name> -- auto - Remove account: $ heroku accounts:remove <name> - Using account: $ heroku accounts:set <name> * Remember: Config (host) in: ~/.ssh/config * More details: ​https://github.com/ddollar/heroku-accounts - Add key: $ heroku keys:add - Ex: Found the following SSH public keys: 1) id_rsa.pub 2) identity.heroku.app_rails.pub 3) identity.heroku.personal.pub 4) identity.heroku.work.pub 5) ssh-add id_rsa.pub Which would you like to use with your Heroku account? => ​3 *More details: ​https://devcenter.heroku.com/articles/keys 11. Config timeout: https://github.com/heroku/rack-timeout http://www.rubydoc.info/gems/rack-timeout/0.0.4/frames
  • 4. 12. Access to db postgres on Heroku - Click to Heroku Postgres Dev on website Heroku application. - In this page, content some info: Host : host_path (ec2-123-321-333.compute-00.compute-1.amazonaws.com) Database: db_name_pg User: user_name Password: password - Connect to database: $ psql -U <username> -h <host> -d <database> $ psql -U user_name -h host_path -d db_name_pg 13. View Memory (RAM), CPU, Core based on dyno sizes: Dyno  Size  Memory  (RAM)  CPU  Share  Multitenan t  Compute  (​2​)  Price/dyno­hou r  1X  512MB  1x  yes  1x­4x  $0.05  2X  1024MB  2x  yes  4x­8x  $0.10  PX  6GB  100% (1)  no  40x  $0.80    *More details:​https://devcenter.heroku.com/articles/dyno-size#available-dyno-sizes 14. Config Domain: - Add domain: $ heroku domain add: <example.com> or add in ​Setting ​section on heroku website.
  • 5. - Get domain default on heroku: http://<my_app>.heroku.com Ex: ​http://my_app.herokuapp.com - Get IP of above domain: $ host ​my_app.herokuapp.com => my_app.herokuapp.com has address ​23.23.80.206 - Go to Godaddy or others service, config your domain point to this IP. More details: ​https://devcenter.heroku.com/articles/custom-domains 15. Upgrade Mongolab ​(From sandbox-free to Single Node SM) Changing to or from a single-node plan on Heroku: 1. Stop your app and any other processes writing to your database 2. Backup your database using mongodump 3. Remove your existing add-on 4. Add a new add-on (see available plans ​here​) 5. Restore your database using mongorestore 6. Change your connection string info in your app 7. Restart your app Example: $ ​mongodump ​-h ds0123456.mongolab.com:3000 -d heroku_app -u user -p password -o . $ heroku addons:remove mongolab $ heroku addons:add mongolab:shared-single-small $ ​mongorestore​-h <new_host>:<new_port> -d heroku_app -u user -p <​new_password​> . * Get ​<​new_password​>: Run : $ ​heroku config | grep MONGOLAB_URI Output: mongodb://heroku_app:​new_password​@​ds0123456​.mongolab.com:3000/heroku_app Compare with: ​mongodb://<dbuser>:<​dbpassword​>@​ds0123456​.mongolab.com:3000/<dbname> Informations account : dbuser: ​dbpassword dbpassword: ​new_password dbname: ​heroku_app * More details: ​https://devcenter.heroku.com/articles/mongolab
  • 6. 16. Improve performance with Unicorn (Concurrency) -​​Add Gem: gem ‘unicorn’ - Config: Create a file configuration for Unicorn at config/unicorn.rb - When using mongoid: worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) timeout 30 preload_app true before_fork do |server, worker| puts worker end after_fork do |server, worker| puts worker end If using Mongoid, you don't need to manually reconnect as in the gist. Mongoid claims: "When using Unicorn or Passenger, each time a child process is forked when using app preloading or smart spawning, Mongoid will automatically reconnect to the master database. If you are doing this in your application manually you may remove your code." (​http://mongoid.org/en/mongoid/docs/rails.html​) * More details:​​https://devcenter.heroku.com/articles/rails-unicorn Other references: http://railsapps.github.io/rails-heroku-tutorial.html https://devcenter.heroku.com/articles/getting-started-with-rails3 * Developer: ​Nguyễn Thành Luân