How To Deploy .NET Core Application On Linux

When Microsoft released their. The main selling point of the Net Core framework was that it is a cross-platform framework, which means that we can now host our. Let’s explore how we can install a net application not only on Windows but also on Linux. Linux net core application


Step 1 – Publish your .Net Core application

First, create a.Net core application in Visual Studio; you can make an MVC project or a Web API project, and if you already have one, open it.

  1. Right-click on your project
  2. Click on publish
  3. Now create a new publish profile, and browse the folder where you want to publish your project dll
  4. Click on publish so it will create your dll in the folder


Step 2 – Install required .Net Module on Linux

Now that we have our web application dll, we must host it on the Linux platform. First, we must grasp how Linux deployment works. Net applications run on Kestrel servers, and in Linux settings, we run Apache or Nginx server, which functions as a proxy server, handling traffic from outside the computer and redirecting it to the Kestrel server, so we have Apache or Nginx server as the middle layer.


In this article, we will use Apache as a proxy server.

To begin, we must install the.Net core module in our Linux environment. Run the following instructions to accomplish this:


  • sudo apt-get update
  • sudo apt-get install apt-transport-https
  • sudo apt-get update
  • sudo apt-get install dotnet-sdk-3.1
  • sudo apt-get install dotnet-runtime-3.1
  • sudo apt-get install aspnetcore-runtime-3.1

Step 3 – Install and configure Apache Server

So we now have everything we need. Internet packages I have installed an additional package that will assist you if you are working on a different project.

Now install the Apache server,

  • sudo apt-get install apache2
  • sudo a2enmod proxy proxy_http proxy_html proxy_wstunnel
  • sudo a2enmod rewrite


Now we need to create a conf file in order to configure our proxy on Apache. Make the following document:

  • sudo nano /etc/apache2/conf-enabled/netcore.conf


Now copy the following configuration in that file,

<VirtualHost *:80>
   ServerName www.DOMAIN.COM
   ProxyPreserveHost On
   ProxyPass /
   ProxyPassReverse /
   RewriteEngine on
   RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
   RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
   RewriteRule /(.*) ws://$1 [P]
   ErrorLog /var/log/apache2/netcore-error.log
   CustomLog /var/log/apache2/netcore-access.log common

<VirtualHost *:80>


This tag specifies the IP address and port to which Apache will be bound, allowing us to access our application from outside our Linux environment via this Ip:Port.

Now restart the Apache server,

  • sudo service apache2 restart
  • sudo apachectl configtest


Step 4 – Configure and Start Service

The command below will move your dll to the specified path.

sudo cp -a ~/release/ /var/netcore/ 

Create a service file for our .Net application

sudo nano /etc/systemd/system/ServiceFile.service”

Copy the following configuration into that file, and our program will operate.


Description=ASP .NET Web Application
ExecStart=/usr/bin/dotnet /var/netcore/Application.dll


ExecStart=/usr/bin/dotnet /var/netcore/Application.dll Replace Application.dll with the name of the dll you wish to start in this line.

Start the service now. Instead of the service name, use the name of the file created above in the following commands.


  • sudo systemctl enable {Service Name}
  • sudo systemctl start {Service Name}

Your proxy server and Kestrel server are now operational, and you may access your application through any IP using port 80.

To redeploy the code, use the following commands to replace the dll and stop and restart your service.


  • sudo systemctl stop {Service Name}
  • sudo systemctl start {Service Name}


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories