This video is available to students only

Deplying to Heroku

In this lesson, we're going to set up Heroku for deployment

After a lot of hard work, we are ready to publish our application. We are going to use Heroku for that. We are using this because it's free of charge and we don't even need a credit card to set up our account here. We can also create free database service with Heroku which is why we chose Postgres over any other database.

Open Heroku and sign up if you haven't. I have an account and this is my dashboard. Click on Create New App; let's give it an app name, learnify-course. You can give it any name as it doesn't matter. Region can stay the same. Now we can click on Create app.

As a deployment method, we are going to use Heroku Git. First of all, we will install Heroku CLI. Choose your operating system and install Heroku CLI on your computer. After installation, we can log in to Heroku through our terminal. Open your terminal and run heroku login. Enter your credentials and after successful login, it will look like this. Before we follow these instructions, we need to set up a few more things.

Let's start with the database, so let's open the hamburger menu and click on databases. We can choose Heroku Postgres and click on Create one. Let's scroll down now and copy this code. We would paste this inside the terminal followed by -a learnify-course. The -a stands for the application. My application name is learnify-course; you can mention your application name here. After setting up the database, we need a buildpack. Let's scroll up and go back to our dashboard.

We can go to Settings and click here for finding the required buildpack. Buildpacks are scripts that are run when your app is deployed. They are used to install dependencies for your app and configure your environment. Let's click here now. We can now search for dotnet — this is the buildpack I'm looking for. Let's click here. Copy this code and paste in our terminal with -a application name. Let's go back to our dashboard now. Inside settings, we need to set up our environment variables. We already have our database url. Let's add some more.

We can open the terminal and run dotnet user-secrets list. Let's copy them and paste in Heroku one by one. Let me add all of them and come back. Now that I have set up all my user-secrets data, we also need to set up two more things here; environment and the token key which is located inside appsettings.development.json file. Let's mention ASPNETCORE_ENVIRONMENT to be Production and JWT:TokenKey to be something strong. You can write any strong string here.

Start a new discussion. All notification go to the author.