preloader
blog-post

Deploying .NET on Debian Linux using PM2 and AWS EC2.

Deploying .NET on Debian Linux using PM2 and AWS EC2

Introduction

Deploying .NET applications on Debian Linux can be a seamless process when combined with tools like PM2 and the flexibility of AWS EC2. This tutorial will guide you through the step-by-step process of deploying a .NET application on Debian Linux using PM2, a process manager for Node.js applications, and the power of Amazon Web Services (AWS) EC2. By the end of this tutorial, you’ll have your .NET application up and running on a Debian Linux server, ready to serve your users.

Prerequisites

Before we begin, you’ll need the following:

  1. An AWS account: Sign up for an AWS account if you don’t have one already.
  2. An EC2 instance: Launch an EC2 instance running Debian Linux.
  3. .NET Core SDK: Install the .NET Core SDK on your local machine for building and publishing the application.
  4. PuTTY (for Windows users): If you’re using Windows, you’ll need PuTTY to connect to your EC2 instance via SSH.

Step 1: Prepare your .NET Application

  1. Build your .NET application using the appropriate .NET Core SDK version.
  2. Publish the application using the following command: dotnet publish -c Release -o <publish_directory>.
  3. Zip the contents of the publish directory: zip -r <application_name>.zip <publish_directory>.

Step 2: Set up your EC2 Instance

  1. Launch a new EC2 instance on AWS.
  2. Choose a suitable Debian Linux AMI (Amazon Machine Image) for your instance.
  3. Configure the security group to allow inbound connections on ports 22 (SSH) and 80 (HTTP).

Step 3: Connect to your EC2 Instance

  1. Use PuTTY (Windows) or the terminal (Linux/macOS) to connect to your EC2 instance via SSH.
  2. Retrieve the public IP address of your instance from the AWS EC2 console.
  3. For Windows users, convert your private key to PuTTY’s format using PuTTYgen.
  4. Connect to your instance using the SSH private key.

Step 4: Install Node.js and PM2 on Debian

  1. Update the package index: sudo apt update.
  2. Install Node.js and npm: sudo apt install nodejs npm.
  3. Install PM2 globally: sudo npm install -g pm2.

Step 5: Transfer and Extract your Application

  1. Transfer the zipped application to your EC2 instance using SCP or SFTP.
  2. Extract the contents of the zip file in a suitable location on your EC2 instance.

Step 6: Configure PM2

  1. Navigate to the application directory: cd <application_directory>.
  2. Start your .NET application with PM2: pm2 start dotnet --name <app_name> -- <app_dll_path>.
  3. Verify that your application is running: pm2 list.

Step 7: Set up Reverse Proxy (Optional)

  1. Install Nginx: sudo apt install nginx.
  2. Configure Nginx as a reverse proxy for your application.
  3. Create an Nginx server block and configure it to forward requests to PM2.

Step 8: Access your Application

  1. Open a web browser and enter the public IP address of your EC2 instance.
  2. If you set up a reverse proxy, your application should be accessible directly through the domain or subdomain configured.

Conclusion

In this tutorial, we explored the process of deploying a .NET application on Debian Linux using PM2 and AWS EC2. By leveraging the power of PM2’s process management capabilities and AWS EC2’s scalable infrastructure, you can easily deploy and manage your .NET applications on a reliable and robust platform. Remember to consider security best practices and optimize your setup for production environments. Happy deploying!

Recent Articles