DEV Community

sajjad hussain
sajjad hussain

Posted on

Unleashing Your ASP.NET Core App: A Guide to Deployment on Ubuntu

The world of web development thrives on a diverse ecosystem of technologies. ASP.NET Core, a powerful framework from Microsoft, empowers developers to build robust and scalable web applications. For those seeking to deploy their ASP.NET Core creations on a cost-effective and versatile platform, Ubuntu emerges as a compelling choice. This article guides you through the process of deploying your ASP.NET Core application on Ubuntu, taking you from development environment to a live server.

Setting the Stage: Prerequisites for Deployment

Before embarking on the deployment journey, ensure you have the following in place:

  • A Developed ASP.NET Core Application: This is the heart of your project! Ensure your application is thoroughly tested and ready for deployment.

  • Ubuntu Server: You can set up a dedicated Ubuntu server on your own hardware or utilize a cloud-based solution offering Ubuntu instances (e.g., DigitalOcean, Amazon Web Services).

  • SSH Client: Secure Shell (SSH) is a secure way to connect to your Ubuntu server remotely. Popular options include PuTTY (Windows) or Terminal (Mac/Linux).

  • Basic Linux Knowledge: Familiarity with basic Linux commands will be beneficial for navigating the server environment.

Gearing Up for Deployment: Configuring the Ubuntu Server

Here's what needs to be done on your Ubuntu server:

  1. Establish a Secure Connection: Connect to your Ubuntu server using your SSH client and login credentials.

  2. Update and Upgrade: Ensure your server is up-to-date by running the following commands:

Bash
sudo apt-get update
sudo apt-get upgrade
Enter fullscreen mode Exit fullscreen mode
  1. Install Dependencies: ASP.NET Core applications rely on the .NET runtime to execute. Install the required dependencies using:
Bash
sudo apt-get install apt-transport-https
sudo apt-get update
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo apt-get install dotnet-sdk-6.0 (Replace 6.0 with your desired .NET SDK version)

Enter fullscreen mode Exit fullscreen mode
  1. Create a Deployment User: For security purposes, it's recommended to create a dedicated user for application deployment. Use sudo adduser (replace with your desired username) and set a strong password.

  2. Configure Firewall (Optional): If needed, configure your firewall to allow access on the port your application will use (typically port 5000).

Building and Publishing for Deployment

Now, let's prepare your ASP.NET Core application for deployment:

  1. Configure Publishing Profile: Within your development environment (Visual Studio, Visual Studio Code), configure a publishing profile for "Folder" deployment. This generates optimized files for deployment.

  2. Publish the Application: Use the publishing profile to create a deployment package. This package typically contains all the necessary DLLs and configuration files.

The Final Step: Uploading and Running the Application

Time to transfer your application to the Ubuntu server:

  1. Secure File Transfer: Use a secure file transfer protocol like SFTP (built-in with most SSH clients) to upload the deployment package to your Ubuntu server (e.g., /var/www/yourapp).

  2. Navigate to Target Directory: Use the cd command to navigate to the directory where you uploaded the deployment package.

  3. Grant Permissions: Ensure the deployment user has ownership and execution permissions for the application files:

Bash
sudo chown -R <deployment_user>:<deployment_user> /var/www/yourapp
sudo chmod -R 755 /var/www/yourapp
Enter fullscreen mode Exit fullscreen mode
  1. Run the Application: Use the following command to launch your application (replace with the actual name of your application assembly):
Bash
dotnet /var/www/yourapp/<your_assembly_name>.dll

Enter fullscreen mode Exit fullscreen mode

How do I get started with the Pine script: Starting Guide for Pine Script

Optional: Setting Up a Service: For a more production-ready setup, consider configuring your application as a systemd service to ensure it automatically restarts on server reboots.

Verifying Success: Accessing Your Application

With the application running on your Ubuntu server, you should be able to access it from a web browser by entering the server's IP address or domain name in the address bar, followed by the port number (e.g., http://your_server_ip:5000).

Top comments (0)