DEV Community

Sheridan
Sheridan

Posted on

How to Deploy your app to Heroku

Hello, this blog is going to explain how to deploy an app that was made with a ruby on rails backend and a react frontend.

To begin you want to create a heroku account, this is free and necessary to use the site to deploy your app.
Image description
Once you have created the account go to your project and sign in to heroku through the terminal.
Image description
It will direct you to the heroku site to log you in.

Disclaimer- before you do anything inside of heroku make sure that you have pushed all your data to github using these commands.
git add . git commit -m "message" and git push
This is what heroku will use to build the app on their site to eventually deploy it.

Ok, now that all your information is updated and you are logged into heroku you want to make sure that heroku is available on your application by running these commands
heroku buildpacks:add heroku/nodejs --index 1
heroku buildpacks:add heroku/ruby --index 2
If they are installed already it will give an error that looks like this Image description

Alright! Almost there!

Next we want to make sure that heroku sees the app that we are building. To push the information to heroku type:
Image description

Now, if everything was set up correctly this command will initiate a long line of code that will take a couple minutes to complete. If everything looks good it should also migrate the information for you. If there is an issue and it says rails aborted you can view the error and fix it accordingly. For more information about what the error is you can use the command:
Image description
It should populate where exactly the application failed.

Side note: if you are using image uploading make sure you are using a public site to upload them to. Meaning somewhere not on your local hard drive. A place where heroku can see. I used AWS and used a bucket to upload my images. I also changed my seeds file in my database to tell the application where to view the images. You also need to include them under the "Config Vars" Image description
Just click reveal confiv vars and put the keys into the key and value areas so heroku knows where to look.

Side side note. Make sure your public keys are in an .env file so that they are available but hidden to the public eye. Learn from my mistakes.

Back to our regularly scheduled program.

Ok, so you should have been able to push and migrate your data. Now we can seed our data. Go ahead and type: Image description
This command may also take a little bit of time. If there is an error there make sure that you type: Image description
to see exactly where the application failed. Be warned, this might be time consuming but you are so close!

If you did run into an error while pushing or seeding your data to heroku you might want to restart your database so heroku has the most up to date information. Use this command Image description

To find the name of your project it will be hereImage description

Don't push it the updated version to heroku just yet. You want to make a slight change to your application so github sees a change. Something as simple as this will do it.Image description

So close, stay with me.

Now that you have restarted your heroku database and made the proper changed to your project, you can go ahead and re-push the information to heroku. If you forgot the command, here it is:Image description

Once again, this should automatically migrate your information to heroku. You can them type in: Image description

When heroku is done seeding it should say something like the "seeding is complete" and will give you a URL. Click that URL and BAM your project is deployed through heroku!

Congrats you did it!

Top comments (0)