Skip to content

Instantly share code, notes, and snippets.

@hamidrhashmi
Last active February 23, 2024 13:33
Show Gist options
  • Save hamidrhashmi/6981c5eabf0cd10b3ac7cbc8334aec0f to your computer and use it in GitHub Desktop.
Save hamidrhashmi/6981c5eabf0cd10b3ac7cbc8334aec0f to your computer and use it in GitHub Desktop.
How to Deploy Dot Net API on Debian 12

STEP 1: Install .NET Runtime

wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

install SDK

sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0

Cehck this link for further information. Check dotnet version

dotnet -version

STEP 2: Download Code

Doenload API code on Server. In my case I have my code in /opt/dotnetAPI/

STEP 3: Create Service file

cat /etc/systemd/system/callhome-bill-api.service

unit file to start .net code

[Unit]
Description=API
Wants=network.target
After=network.target

[Service]
Environment="ASPNETCORE_URLS=http://*:5000"
Environment="ASPNETCORE_WEBROOT=/opt/dotnetAPI/"
Environment="ASPNETCORE_CONTENTROOT=/opt/dotnetAPI/"
ExecStart=/usr/bin/dotnet /opt/dotnetAPI/API.dll
ExecStop=/bin/kill ${MAINPID}
Restart=on-failure
RestartSec=5s
Type=simple

[Install]
WantedBy=multi-user.target

Dot Net Envoirnmnet Variables

Check this link for compiling dotnet code on linux

Enjoy ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment