Deploying the ASP.NET Core web application in the Linux environment

In this section of the chapter, we are going to learn how to create and deploy the ASP.NET Core web application in the Linux platform. I am going to deploy the application in the cloud using Amazon Web Services (AWS). Obviously, you don't need AWS to deploy the ASP.NET Core application on Linux. I am just using it so that I do not need to install Linux on my local machine. And another advantage of hosting with AWS (or any other public cloud service provider or any hosting provider) is that I can access the web application from anywhere as it will be publicly available.

We have the following prerequisites to create and deploy in the Linux environment:

  • Linux machine
  • Putty client (if you are using a remote Linux machine)

Creating a Linux machine

We are going to use AWS to create a Linux machine. The advantage of using AWS or any other cloud provider is that we can use their service only when we need it and we can wind down the machine when you are done with it. You only need to pay for the time when you are using it. For the first year, AWS has a free tier where you can host the machine (if it is eligible for the free tier) without having to pay anything. I have been using AWS for more than couple of years to try out many things in the cloud, hence I am not eligible for the free tier.

However, you can install Linux on your Windows PC by using any virtualization software. Ubuntu Linux has the option of booting up from the USB drive itself so that you don't need to disturb anything in your local PC.

Once you sign-up for an AWS account, you can go to the EC2 dashboard, where you can create EC2 instances:

Creating a Linux machine

Click Launch Instance in the preceding screen. A wizard will be launched where it will help you in selecting and configuring the instances. In this step, we are selecting the Ubuntu Linux server because of its ease of use.

Creating a Linux machine

There are different kinds of instances available in AWS ranging from nano (with 0.5 GB RAM) to large machines (with 1952 GB RAM). We are going to choose micro instance as it is eligible for the free tier:

Creating a Linux machine

In previous step, we can configure the instances for the cloud. We can create an auto scale group where the AWS cloud will spin up the instances automatically when the load is high. As our objective is to create and deploy the ASP.NET Core web application, we are going to leave the default values as they are and click Next: Add Storage to move to the next screen:

Creating a Linux machine

The micro instances do not come with any external storage. Hence, we need to add the storage in order to use it. We have three options for storage to choose from: General Purpose SSD, Provisioned SSD, and Magnetic SSD. Out of the three, the General Purpose SSD is the storage that would be usually used.

When your application is making high input-output operations, the throughput may come down. But in the Provisioned SSD you can maintain the required throughput from the storage device. Magnetic storage is just an old type of storage. We are going to use the General Purpose 8 GB Solid State Drive (SSD) as it serves our purpose well.

Creating a Linux machine

If you are using multiple instances, you can tag them so that you can control the instances by using the tag name. As we are going to launch only one instance, I am just going to leave it blank and move on to the next step:

Creating a Linux machine

In this step, we can configure the security group for the instance—which ports should be opened for the incoming traffic. The general rule in any configuration is to only open up the ports what you need and nothing else. You also need to tell the IP (or its range) from where the machine could be accessed from. As it is a demo application, we are going to open ports 22, for Secure Shell (SSH); for using PuTTY, and 80, for accessing the Core web application.

Once you have configured the Security Groups, click Review and Launch.

Creating a Linux machine

On the following screen, you can review the chosen options:

Creating a Linux machine

You can click Launch once you are fine with the selected options. Otherwise, you can go back to the previous step to reconfigure them with the correct values.

When you click Launch, it will ask you to choose a key pair which you will be using to log into any AWS server. If you do not have one, you can create one. As I have created one already, I am going to use the existing one, as shown in the following screenshot:

Creating a Linux machine

Select the key pair and click Launch Instances. AWS will spin up new instances for us and the status will be shown (as in the following screenshot). The instance ID will also be available (boxed in the screenshot):

Creating a Linux machine

Clicking on the blue colored link will fetch you the status (as shown in the following screenshot). The Public DNS and Public IP are important values which you will be using to connect to that server. Hence, I've boxed them in the screenshot:

Creating a Linux machine

Installing the PuTTY client

Having created a new Linux server where we can create an ASP.NET 5 web application and host it, we need to install the PuTTY client, a small application that can send commands to the Linux server and receive the responses. As we are going to install the application in a Linux server, we need to have a way for connecting from your Windows PC to the Linux server. The PuTTY client application does exactly that.

You can download the PuTTY client by visiting http://www.chiark.greenend.org.uk/~sgtatham/putty/ .

Installing the PuTTY client

Click on the Download link and select the link (boxed in the screenshot) in the following screen:

Installing the PuTTY client

It will download the MSI file. Once it's downloaded, launch the installer and you'll be shown the following welcome screen:

Installing the PuTTY client

Click Next and you'll see following screen:

Installing the PuTTY client

Choose the installation folder—you can leave it as it is and click Next:

Installing the PuTTY client

Select the product features which you want to install. You can leave the default selection and click Install. Once it is installed, you will be shown the following screen:

Installing the PuTTY client

Click Finish and launch the PuTTY application. It will open the PuTTY configuration window, where we are going to enter the hostname and authentication details. The hostname is <username>@<public DNS>. In our case, it is [email protected]. Ubuntu is the default user for the Ubuntu AMI that we have chosen. We can get the public DNS value in the status window as shown earlier:

Installing the PuTTY client

For authentication, select Connection | SSH | Auth in the left-hand pane and select the PPK file (private key file) that we created earlier:

Installing the PuTTY client

Click Open. You'll get a warning asking you whether you trust this host. Click yes and you'll be shown the Command Prompt of the Linux screen.

Installing the PuTTY client

Next, we need to install .NET Core before creating the ASP.NET 5 application and eventually host them.

Installing of .NET Core in a Linux machine

In order to install .NET Core on Ubuntu, we need to first set up the apt and get feed that hosts the package that we need. Enter the following commands:

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893

You will get the following screen:

Installing of .NET Core in a Linux machine

Then update it by issuing the following command, which will download the required packages and install them:

sudo apt-get update

You will see the following screen for this command:

Installing of .NET Core in a Linux machine

Install the .NET Core with the following command:

sudo apt-get install dotnet-dev-1.0.0-preview2-003121

The following screen will be displayed:

Installing of .NET Core in a Linux machine

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset