How to deploy .NET Core app on Linux Server

Published at 26 Feb 2026

How to deploy .NET Core app on Linux Server

1. Prerequisites

  1. We will start from a newly installed Linux Ubuntu 24.04 server.
  2. No external firewall from your server provider
  3. We will start from scratch, no server yet.
  4. We will not use docker (for now)

2. Purchase Linux Server

2.1. Get Linux Ubuntu Server VPS

First, what you have to do is get a Linux Ubuntu 24.04 Server VPS.

After getting a Linux Ubuntu 24.04 Server VPS, you need to get these:

  1. IP address of your server
  2. Username and Password (for SSH access)

3. Domain

3.1. Buy Domain

Purchase your domain. You can purchase from Namecheap.

You can follow a video guide here: How to Buy Your Own .com Domain Name on Namecheap

3.2. Update your DNS

Point your DNS to your server.

4. Publish your app for Linux

First, build the solution

dotnet build --configuration

Second, publish for linux.

dotnet publish $(netCoreApiProjectName) --configuration $(netCoreApiBuildConfiguration) --self-contained true -r linux-x64

We use a self-contained build so that you do not have to do too much configuration on the server.

5. Set up Linux server (Part 1)

5.1. Install PutTy

PuTTy is a SSH client. You need an SSH client to access your ubuntu server. https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

5.2. Access your server

Use PuTTy to access your server. Use the IP Address, username and password previously.

Create folders

This is the way I prefer to structure my servers:

/srv/[domain]/www
/srv/[domain]/misc

Example if my domain is miaw.xyz:

/srv/miaw.xyz/www
/srv/miaw.xyz/misc

You can create the folders with this command:

mkdir /srv/[domain]/www
mkdir /srv/[domain]/misc

Continue later

We need to continue setting up this server later.

Copy your files to server

.tar.gz your files

We’re going to archive your files for easier upload. But instead of zip, we’re going to use tar instead.

Now, open command promt and cd to the published folder.

Use this command to tar the contents of the published folder.

tar -czvf publish.tar.gz folder/

In my above example:

tar -czvf publish.tar.gz c:/dev/miawxyz/publish/

The ending backslash is important to signify that we only want to tar the contents of the folder, not the folder itself.

Copy to server

To copy to the server, we can use the scp command.

scp publish.tar.gz [username]@[ipaddress]:[path]

Example:

scp publish.tar.gz root@123.123.123.123:/srv/miaw.xyz/misc

Untar on server

ssh to the server again. Now we need to untar it to the www folder.

tar -xzvf /srv/[domain]/misc/publish.tar.gz /srv/[domain]/www/ --strip-components 1

It will unarchive the contents of the publish.tar.gz into the www/ folder (without including the ‘publish’ folder).

Setup linux server (Part 2)

Install node

Install nvm (Node Version Manager)

https://github.com/nvm-sh/nvm

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
Install node version
nvm install --lts
nvm use
nvm use <version>

pm2

Install

npm install pm2 -g

Set environment variables (IMPORTANT!)

ASPNETCORE_FORWARDEDHEADERS_ENABLED: true ASPNETCORE_ENVIRONMENT: Production

Run the .NET Core app

pm2 start —name $(netCoreApiPm2ProcessName) “dotnet $(netCoreApiProjectDll) —urls=’$(netCoreDotnetUrl)‘”

Ensure it runs again on reboot

pm2 startup

Execute the command given

Caddy Server

Many people may use nginx, but in this tutorial we’re going to use Caddy Server.

Pluses

  • Easy to setup
  • Auto SSL, no need anymore configuration
  • Easy configuration using caddyfile

Install

Caddy file

Point to the .NET Core app

You did it!

Yeah!

Extra

Firewall

Set up firewall