What is Heroku?
Heroku is the container-based cloud Platform service provider, that provide wide range of services. Heroku build, deliver monitor and scale applications fastest way. Using heroku you can bypass lot of headaches and minimise deployment efforts.
Mostly Used heroku commands
How to create new repository?
heroku create [new-repository-name]: This command create new empty heroku application with the specified name and initialise the new application with empty git repository. You can check the new created remote with git remote -v command.
How to set remote to existing application?
heroku git:remote -a [remote-address]: Using this command you can add remote to your existing application.
How to rename remote at heroku?
git remote rename [current-remote] [new-remote-name]: Using this command you can rename to existing application remote name, so if new-remote-name is not already in used than it will be updated.
How to restart heroku application?
heroku restart: Using this command you can restart the application at heroku, it will by default restart all the available dynos, you can restart
to only specific dynos by specifying the name of dynos as “heroku restart web”, this will only restart the web dynos only.
What is the heroku dynos?
Heroku dynos are isolated, virtulized, linux containers which are designed to execute the code based on user specified commands.
How to check the status of heroku platform?
heroku status: Using this command you can check the status of heroku platform, if there any scheduled maintenance or critical error on heroku server than this command will show the info about the issue.
How to open heroku application in browser using heroku cli?
heroku open: using this command you can open the heroku application directly in browser.
How to backup database from heroku?
heroku pg:backups:capture: This command will create the new backup file with curret database. heroku pg:backups:download: Using this command you can download the database backup file at your local system.
How to restore heroku database?
heroku pg:backup:restore [signed URL] DATABASE_URL: Using this command you can restore heroku database from signed url. Before creating
signed url you need to create backup copy of database from your local system if you are restoring from local system database.
for this you can use following command to create local backup with pg_dump: PGPASSWORD=mypassword pg_dump -Fc –no-acl –no-owner -h localhost -U myuser mydb > mydb.dump, Once you have created the backup dump file, you need to store it in live server like aws, cloudinary etc., because heroku only accept the live url only for database restore, you generate signed url with aws with following command “aws s3 presign s3://your-bucket-address/your-object ” in above DATABASE_URL is the HEROKU_POSTGRESQL_COLOR_URL of the database, you must specify a database configuration variable to restore the database.
How to check the logs for heroku application?
heroku logs [options]: Using this command we can check the logs for heroku application, using the option -t we can view live logs for heroku application, like heroku logs -t.
What are the uses of heroku run command?
Heroku run [option]: This command the used to specific task on one of the dynos. Like we can rake tasks using this command as bellow; heroku run rake db:migrate, heroku run rake db:setup, we also can open console using “heroku run rake console” command.
heroku run bash: Using this command, you can open bash window from heroku to run bash command just like we use SSH.
How to view last made changes on heroku?
heroku releases: Using this command we can view lastly made changes, it can be change in dynos, rake tasks or add/update ENV variable.
How to rollback at heroku?
heroku rollback [‘# release’]: Using with this command heroku can rollback last change with specified [#release], the changes will be temporarily so you can pull the changes can work on it and push again by making required changes.
What is the Buildpacks?
Buildpacks is script that is heroku uses to deploy the application.
What is Forking at heroku and how heroku manage multiple Heroku apps?
Forking is the way of heroku to mange multiple versions of same application like development, staging, production etc. To use fork command we must need to install fork plugin with bellow command
heroku plugins:install heroku-fork: This will install the heroku fork plugin. heroku fork -a [curretapp] [targetapp]: Using this command we can create new version of existing application, by coping all the existing dynos, ENV variables, database etc over new slug. for more details go the the oficial heroku documentation link. Heroku will not create new repository to new-forkedapp, if you wish you need to create new repository and add it with bellow command:
git remote add forked email@example.com:targetapp.git: It will add remote to forked application. now you can deploy to new environment.
git push forked master: With this command we can deploy the code to new environment.
How can rename forked application?
git remote rename heroku old:
git remote rename forked to origin: This set new environment to default environment.
How to setup error page and maintenance page url at heroku?
We can set error pages and maintenance pages url with ENV variables named ERROR_PAGE_URL and MAINTENANCE_PAGE_URL respectively.
What are the Deploy hooks?
These are the callbacks that run when code is deployed to heroku. We can set these callbacks to send notifications as email or sms to developers to notify about finish of deployment process at heroku.