Hosting on Ubuntu Linux 20.04

Case Details

May 19, 2022

Publish .Net 6.0 Web App on Ubuntu Linux 20.04

A Step by Step guide to creating Web App and Publish on Linux

1. Create a new project and select the ASP.NET Core Web App


2. Specify your Project name, location, and Solution name to Configure your project


3. Specify framework to .Net 6.0 latest one


4. Your project is almost ready and looks like this one.


5. Configure a reverse proxy server in the application

After creating the project next, we are going to make changes in Configure method in the Startup class we are going to add UseForwardedHeaders middleware.

6. Do some additional configuration.

Mainly need to do app.UseForwardedHeaders(); app.UseHttpsRedirection(); and app.UseEndpoints(endpoints =>


Supported distributions

The following table is a list of currently supported .NET releases and the versions of Ubuntu they're supported on. These versions remain supported until either the version of .NET reaches end-of-support or the version of Ubuntu reaches end-of-life.

  • A indicates that the version of Ubuntu or .NET is still supported.
  • A indicates that the version of Ubuntu or .NET isn't supported on that Ubuntu release.
  • When both a version of Ubuntu and a version of .NET have , that OS and .NET combination is supported.

Ubuntu .NET Core 3.1 .NET 5 .NET 6
21.10 3.1 5.0 6.0
21.04 3.1 5.0 6.0
20.10 3.1 5.0 6.0
20.04 (LTS) 3.1 5.0 6.0
19.10 3.1 5.0 6.0
19.04 3.1 5.0 6.0
18.10 3.1 5.0 6.0
18.04 (LTS) 3.1 5.0 6.0
17.10 3.1 5.0 6.0
17.04 3.1 5.0 6.0
16.10 3.1 5.0 6.0
16.04 (LTS) 3.1 5.0 6.0

The following versions of .NET are no longer supported. The downloads for these still remain published:

  • .NET Core 3.0
  • .NET Core 2.2
  • .NET Core 2.1
  • .NET Core 2.0

7. Connecting to Linux Server using PuTTY

For connecting to Linux Virtual Machine, we are going to use the PuTTY URL for downloading putty

To get a Public IP address to connect to your VM just click on Home Menu from the sidebar then you can Recent resources from that choose recently Create Virtual Machine you will see a similar screen as shown below.

Let’s start PuTTY for connecting to the Virtual Machine. Enter your public IP address in Host Name and Port will be 22 as shown in the above screenshot and click on the Open button to connect.


Enter your username which you have set while creating the Virtual Machine.


And enter a Password


After connecting the terminal, we are going to run some installation in it.

8. Register the Microsoft Product key as trusted

We are going to run this command in the terminal.

wget -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

9. Install .Net

In this step we are going to install .NET Core Runtime allows you to run apps that were made with .NET 6.0

Install the SDK

sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-6.0

Install the runtime

sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y aspnetcore-runtime-6.0

10. Publishing the Application

Publish application on local (windows) IIS


Publish Files

Publish-.Net-6.0-Web-App <

Your web application is up and running on local IIS.

Publish-.Net-6.0-Web-App <

After publishing, we need to copy files to Linux Machine for doing that we are going to use WinSCP tool.

11. Copying Application to Linux Server

In this step, we are going to copy that folder to Linux Virtual Machine for doing that we are going to use WinSCP. URL to Download WinSCP: –


12. Install Apache

In this step, we are going to install the Apache webserver.

sudo apt install apache2

13. Check Apache Server Status

Next, we have installed Apache now we can check the Apache webserver status is it running.

sudo systemctl status apache2

Publish-.Net-6.0-Web-App <

To test in the browser, just access from Public IP. It will show you the default Apache web page as shown below.


14. Enable the required apache modules

sudo a2enmod rewrite
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headers
sudo a2enmod ssl

Run each command one by one. After Enabling modules, the Apache server needs to restart.

15. Restart Apache

Here we are going to restart the Apache server after Enabling Modules in the last step.

sudo service apache2 restart

16. Create a Folder in the www folder and copy all application files

In step 11 we have copied files to /home/devadmin/publish/ folder now we are going copy those files to /var/www/publishapplication/ folder. Before copying, we are going to create a folder.

sudo mkdir -p /var/www/publishapplication/publish/

mkdir -p command
With the help of mkdir -p command, you can create subdirectories of a directory. It will create a parent directory first if it doesn’t exist. But if it already exists, then it will not print an error message and will move further to create sub-directories.

Copy files to newly created folder /var/www/publishapplication/Publish folder.

sudo cp -r /home/devadmin/publish/ /var/www/publishapplication/

You can view this folder using WinSCP tool and navigate to /var/www/publishapplication/

cp -r command

Option ‘r’ with the copy command can be used to copy a directory including all its content from a source directory to the destination directory.

17. Create a Virtual Host configuration File

Apache Virtual Host Configuration are located in /etc/apache2/sites-available

I am going to name Virtual Host Configuration file as webapplicationfile.conf many people give the domain name to the Configuration file for easy to recognize.

sudo nano /etc/apache2/sites-available/webapplicationfile.conf

18. Add the below content to webapplicationfile.conf

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://localhost:5000/
    ProxyPassReverse / http://localhost:5000/
    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule /(.*) ws://$1 [P]
    ErrorLog ${APACHE_LOG_DIR}/
    CustomLog ${APACHE_LOG_DIR}/ combined


After adding this content just save the file by pressing Crtl + S. Then press Ctrl + x to jump back from this window and back to a terminal window.

19. Disable the default site defined in 000-default.conf

sudo a2dissite 000-default.conf

After disabling the site next defined in 000-default.conf file next, we are going to activate current configured virtual host configuration file.

20. Activate the webapplicationfile.conf

Here we are going to enable webapplicationfile.conf file.

sudo a2ensite webapplicationfile.conf

21. Check the syntax of the Default Configuration file

sudo apachectl configtest

If the message of the terminal is Syntax OK then your configuration file is proper


22. Restart Apache2 to make to take new changes

sudo systemctl restart apache2

23. Creating service

Creating a systemd Service file with the name webapplicationfile.service

sudo nano /etc/systemd/system/dotnet6servicefile.service

Paste the following contents into the service file.

Description=Running ASP.NET Core on Ubuntu 18.04 Webserver APACHE

ExecStart=/usr/bin/dotnet /var/www/publishapplication/publish/DotNet6.dll
# Restart service after 10 seconds if the dotnet service crashes:


WorkingDirectory= defines in which directory the service will be launched. This my application publish folder /var/www/publishapplication/publish

ExecStart= allows you to specify any command that you’d like to run when this service is started.

Save this file by pressing Ctrl + s.

24. Enable the service

sudo systemctl enable dotnet6servicefile.service

25. Start the service

sudo systemctl start dotnet6servicefile.service

26. Output


Your .Net 6.0 Web App is successfully hosted on Linux Ubuntu 20.04 and the web app is up & running.

All this setup and configuration is credited to this article

Project Details
  • Technology: .Net 6.0
  • Database: MS SQL
  • Platform: Linux Ubuntu 20.04

Related Case Studies