+
arch
f#
+
laravel
+
goland
+
+
+
gcp
--
+
+
axum
+
+
<-
spring
+
+
โˆ‰
+
โ‰ˆ
_
+
+
+
+
ubuntu
objc
+
!==
yarn
+
angular
actix
+
spring
+
fauna
tcl
haiku
+
py
aurelia
->
+
+
+
nvim
+
+
soap
+
+
+
+
+
โŠ‚
fauna
clion
spacy
+
+
++
rollup
+
symfony
html
emacs
php
cdn
crystal
+
+
aws
raspbian
+
+
deno
eclipse
+
+
+
+
websocket
spacy
+
+
Back to Blog
๐Ÿ”ท .NET Core Applications on AlmaLinux: Complete Deployment Guide
AlmaLinux .NET Core ASP.NET Core

๐Ÿ”ท .NET Core Applications on AlmaLinux: Complete Deployment Guide

Published Sep 13, 2025

Master .NET Core and ASP.NET Core deployment on AlmaLinux! Learn installation, Kestrel configuration, reverse proxy setup, Docker deployment, and production best practices. Perfect for Microsoft developers embracing Linux.

5 min read
0 views
Table of Contents

๐Ÿ”ท .NET Core Applications on AlmaLinux: Complete Deployment Guide

Welcome to the cross-platform revolution of .NET development! ๐Ÿš€ Today weโ€™ll master deploying .NET Core and ASP.NET Core applications on AlmaLinux, bringing the power of Microsoftโ€™s framework to the stability of enterprise Linux. Think of this as breaking down barriers - your C# applications can now run everywhere! ๐ŸŒ

Gone are the days when .NET meant Windows-only. With .NET Core (now .NET 5/6/7/8), Microsoft has embraced open source and Linux, making it possible to run high-performance .NET applications on AlmaLinux servers. Letโ€™s unlock this powerful combination! ๐Ÿ’ช

๐Ÿค” Why is .NET Core on Linux Important?

.NET Core on Linux is a game-changer for enterprise development! โšก Hereโ€™s why it matters:

  • ๐Ÿš€ Blazing Performance - .NET Core is one of the fastest web frameworks available
  • ๐Ÿ’ฐ Cost Savings - No Windows Server licenses required
  • ๐Ÿง Linux Benefits - Leverage Linuxโ€™s stability, security, and tooling
  • ๐ŸŒ True Cross-Platform - Develop on Windows, Mac, or Linux, deploy anywhere
  • ๐Ÿ“ฆ Container Ready - Perfect for Docker and Kubernetes deployments
  • ๐Ÿข Enterprise Support - Microsoft fully supports .NET on Linux
  • โšก Modern Framework - Built for cloud-native and microservices
  • ๐Ÿค Massive Ecosystem - Access to NuGet packages and .NET libraries

๐ŸŽฏ What You Need

Before deploying .NET applications on Linux, ensure you have:

โœ… AlmaLinux system (physical or virtual machine)
โœ… Root or sudo access for installing .NET runtime
โœ… At least 1GB RAM (2GB+ recommended for development)
โœ… Basic C# knowledge (helpful but weโ€™ll guide you)
โœ… Text editor like nano, vim, or VS Code
โœ… Internet connection for downloading packages
โœ… Basic command line skills (weโ€™ll explain everything!)
โœ… 10GB free disk space for SDK and applications

๐Ÿ“ Installing .NET on AlmaLinux

Letโ€™s install the latest .NET SDK and runtime! ๐Ÿ› ๏ธ

# Update your system first
sudo dnf update -y
# Ensures you have the latest packages

# Install Microsoft package repository
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
# Adds Microsoft's official .NET repository

# Install .NET SDK (includes runtime)
sudo dnf install -y dotnet-sdk-8.0
# Installs .NET 8 SDK (latest LTS version)

# Install ASP.NET Core runtime (if you only need runtime)
sudo dnf install -y aspnetcore-runtime-8.0
# For production servers that don't need SDK

# Verify installation
dotnet --version
# Should show: 8.0.x

dotnet --list-sdks
# Shows all installed SDK versions

dotnet --list-runtimes
# Shows all installed runtime versions

# Install useful development tools
sudo dnf install -y git wget curl
# Tools for development and deployment

Set up environment variables:

# Add .NET tools to PATH
echo 'export PATH=$PATH:$HOME/.dotnet/tools' >> ~/.bashrc
echo 'export DOTNET_CLI_TELEMETRY_OPTOUT=1' >> ~/.bashrc
source ~/.bashrc
# Configures .NET environment

# Install Entity Framework tools (for database work)
dotnet tool install --global dotnet-ef
# Installs EF Core command-line tools

# Install code formatting tool
dotnet tool install --global dotnet-format
# Helps maintain consistent code style

๐Ÿ”ง Creating Your First ASP.NET Core Application

Letโ€™s build a web API to demonstrate deployment! ๐Ÿ—๏ธ

# Create a new ASP.NET Core Web API project
dotnet new webapi -n MyApi -o ~/MyApi
cd ~/MyApi
# Creates a new Web API project

# Create a simple controller
cat > Controllers/HelloController.cs << 'EOF'
using Microsoft.AspNetCore.Mvc;

namespace MyApi.Controllers;

[ApiController]
[Route("api/[controller]")]
public class HelloController : ControllerBase
{
    private readonly ILogger<HelloController> _logger;
    
    public HelloController(ILogger<HelloController> logger)
    {
        _logger = logger;
    }
    
    [HttpGet]
    public IActionResult Get()
    {
        return Ok(new 
        {
            Message = "Hello from .NET on AlmaLinux! ๐Ÿš€",
            Timestamp = DateTime.UtcNow,
            Platform = System.Runtime.InteropServices.RuntimeInformation.OSDescription,
            DotNetVersion = Environment.Version.ToString()
        });
    }
    
    [HttpGet("{name}")]
    public IActionResult GetByName(string name)
    {
        _logger.LogInformation($"Greeting requested for {name}");
        return Ok(new 
        {
            Message = $"Hello {name}! Welcome to .NET on Linux! ๐ŸŽ‰",
            ServerTime = DateTime.UtcNow
        });
    }
    
    [HttpPost]
    public IActionResult Post([FromBody] UserData data)
    {
        return Created("", new 
        {
            Id = Guid.NewGuid(),
            Name = data.Name,
            Email = data.Email,
            CreatedAt = DateTime.UtcNow
        });
    }
}

public class UserData
{
    public string Name { get; set; } = "";
    public string Email { get; set; } = "";
}
EOF
# Creates a sample API controller

# Test the application locally
dotnet run
# Starts the development server

# In another terminal, test the API
curl http://localhost:5000/api/hello
# Should return JSON response

# Build for production
dotnet publish -c Release -o ./publish
# Creates optimized production build

๐ŸŒŸ Configuring Kestrel Web Server

Kestrel is .NETโ€™s cross-platform web server! ๐Ÿš€

# Configure Kestrel settings
cat > appsettings.Production.json << 'EOF'
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://0.0.0.0:5000"
      },
      "Https": {
        "Url": "https://0.0.0.0:5001",
        "Certificate": {
          "Path": "/etc/ssl/certs/mycert.pfx",
          "Password": "CertPassword123!"
        }
      }
    },
    "Limits": {
      "MaxConcurrentConnections": 100,
      "MaxConcurrentUpgradedConnections": 100,
      "MaxRequestBodySize": 52428800,
      "RequestHeadersTimeout": "00:01:00"
    }
  },
  "AllowedHosts": "*"
}
EOF
# Configures Kestrel for production

# Update Program.cs for production configuration
cat > Program.cs << 'EOF'
var builder = WebApplication.CreateBuilder(args);

// Add services
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// Configure Kestrel
builder.WebHost.ConfigureKestrel(serverOptions =>
{
    serverOptions.Limits.MaxConcurrentConnections = 100;
    serverOptions.Limits.MaxConcurrentUpgradedConnections = 100;
    serverOptions.Limits.MaxRequestBodySize = 52428800; // 50MB
    serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(2);
    serverOptions.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(1);
});

// Add CORS
builder.Services.AddCors(options =>
{
    options.AddPolicy("AllowAll",
        policy => policy.AllowAnyOrigin()
                       .AllowAnyMethod()
                       .AllowAnyHeader());
});

var app = builder.Build();

// Configure pipeline
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseCors("AllowAll");
app.UseAuthorization();
app.MapControllers();

// Add health check endpoint
app.MapGet("/health", () => Results.Ok(new { Status = "Healthy", Time = DateTime.UtcNow }));

app.Run();
EOF
# Configures the application startup

โœ… Creating a Systemd Service

Letโ€™s make our .NET app run as a service! ๐ŸŽฏ

# Create systemd service file
sudo cat > /etc/systemd/system/dotnet-myapi.service << 'EOF'
[Unit]
Description=.NET Core API on AlmaLinux
After=network.target

[Service]
Type=notify
User=dotnetuser
Group=dotnetuser
WorkingDirectory=/var/www/myapi
ExecStart=/usr/bin/dotnet /var/www/myapi/MyApi.dll
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-myapi

# Environment variables
Environment="ASPNETCORE_ENVIRONMENT=Production"
Environment="DOTNET_PRINT_TELEMETRY_MESSAGE=false"
Environment="ASPNETCORE_URLS=http://0.0.0.0:5000"

# Limits
LimitNOFILE=100000
LimitNPROC=4096

# Hardening
PrivateTmp=true
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
EOF
# Creates systemd service for automatic startup

# Create user for running the service
sudo useradd -r -s /bin/false dotnetuser
# Creates system user for security

# Deploy application files
sudo mkdir -p /var/www/myapi
sudo cp -r ~/MyApi/publish/* /var/www/myapi/
sudo chown -R dotnetuser:dotnetuser /var/www/myapi
# Copies application to production location

# Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable dotnet-myapi
sudo systemctl start dotnet-myapi
# Starts the .NET application

# Check service status
sudo systemctl status dotnet-myapi
# Should show "active (running)"

# View logs
sudo journalctl -u dotnet-myapi -f
# Shows real-time application logs

๐ŸŽฎ Quick Examples

Letโ€™s explore practical .NET deployment scenarios! ๐ŸŽฏ

Example 1: Nginx Reverse Proxy Configuration

# Install Nginx
sudo dnf install -y nginx

# Configure Nginx for .NET Core
sudo cat > /etc/nginx/conf.d/dotnet-app.conf << 'EOF'
server {
    listen 80;
    server_name your-domain.com;
    
    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
        
        # Timeouts
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
        
        # Buffering
        proxy_buffering off;
        proxy_buffer_size 4k;
        proxy_buffers 8 4k;
    }
    
    # WebSocket support for SignalR
    location /hub {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
EOF

# Test and restart Nginx
sudo nginx -t
sudo systemctl restart nginx
# Applies reverse proxy configuration

Example 2: Docker Deployment

# Create Dockerfile for .NET application
cat > Dockerfile << 'EOF'
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

# Copy project file and restore dependencies
COPY *.csproj .
RUN dotnet restore

# Copy everything and build
COPY . .
RUN dotnet publish -c Release -o /app

# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app .

# Create non-root user
RUN useradd -m -s /bin/false dotnetuser && chown -R dotnetuser:dotnetuser /app
USER dotnetuser

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:5000/health || exit 1

EXPOSE 5000
ENTRYPOINT ["dotnet", "MyApi.dll"]
EOF

# Build Docker image
docker build -t myapi:latest .

# Run Docker container
docker run -d -p 5000:5000 --name myapi \
  -e ASPNETCORE_ENVIRONMENT=Production \
  myapi:latest

# Check container logs
docker logs myapi

Example 3: Database Integration with Entity Framework

# Install PostgreSQL provider
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL

# Create database context
cat > Data/AppDbContext.cs << 'EOF'
using Microsoft.EntityFrameworkCore;

namespace MyApi.Data;

public class AppDbContext : DbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options) 
        : base(options) { }
    
    public DbSet<User> Users { get; set; }
    public DbSet<Product> Products { get; set; }
}

public class User
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
    public string Email { get; set; } = "";
    public DateTime CreatedAt { get; set; }
}

public class Product
{
    public int Id { get; set; }
    public string Name { get; set; } = "";
    public decimal Price { get; set; }
    public int Stock { get; set; }
}
EOF

# Configure database in Program.cs
cat >> Program.cs << 'EOF'

// Add database context
builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
EOF

# Add connection string to appsettings
cat >> appsettings.json << 'EOF'
,
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=myapi;Username=apiuser;Password=ApiPass123!"
  }
EOF

# Run migrations
dotnet ef migrations add InitialCreate
dotnet ef database update
# Creates database schema

๐Ÿšจ Fix Common Problems

Encountering issues? Here are solutions:

Problem 1: Port Already in Use

# Check what's using port 5000
sudo netstat -tlnp | grep :5000
# Shows process using the port

# Kill the process if needed
sudo kill -9 <PID>
# Replace <PID> with process ID

# Or change the port in appsettings.json
"Kestrel": {
  "Endpoints": {
    "Http": {
      "Url": "http://0.0.0.0:5050"
    }
  }
}

Problem 2: SSL Certificate Issues

# Generate development certificate
dotnet dev-certs https --trust
# Creates and trusts development certificate

# For production, use Let's Encrypt
sudo dnf install -y certbot
sudo certbot certonly --standalone -d your-domain.com

# Convert to PFX for .NET
openssl pkcs12 -export -out certificate.pfx \
  -inkey /etc/letsencrypt/live/your-domain.com/privkey.pem \
  -in /etc/letsencrypt/live/your-domain.com/cert.pem \
  -certfile /etc/letsencrypt/live/your-domain.com/chain.pem

Problem 3: Permission Denied Errors

# Fix directory permissions
sudo chown -R dotnetuser:dotnetuser /var/www/myapi
sudo chmod 755 /var/www/myapi

# Fix SELinux context (if enabled)
sudo setsebool -P httpd_can_network_connect 1
sudo chcon -R -t httpd_sys_content_t /var/www/myapi

# Check current permissions
ls -la /var/www/myapi/

Problem 4: Application Wonโ€™t Start

# Check service logs
sudo journalctl -u dotnet-myapi -n 100
# Shows last 100 log entries

# Run application manually to see errors
cd /var/www/myapi
sudo -u dotnetuser dotnet MyApi.dll
# Shows startup errors directly

# Check for missing dependencies
ldd /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.0/*.so | grep "not found"
# Shows missing libraries

# Reinstall .NET runtime if needed
sudo dnf reinstall aspnetcore-runtime-8.0

Problem 5: High Memory Usage

# Configure garbage collection
export DOTNET_gcServer=false  # Use workstation GC
export DOTNET_GCHeapCount=2   # Limit heap count

# Add to service file
Environment="DOTNET_gcServer=false"
Environment="DOTNET_GCHeapCount=2"

# Monitor memory usage
dotnet-counters monitor -p $(pgrep dotnet)
# Shows real-time performance counters

# Enable memory dumps for analysis
export COMPlus_DbgEnableMiniDump=1
export COMPlus_DbgMiniDumpType=4

๐Ÿ“‹ Simple Commands Summary

Hereโ€™s your .NET on Linux quick reference! ๐Ÿ“–

CommandPurposeExample
dotnet new webapiCreate new APIdotnet new webapi -n MyApp
dotnet runRun applicationdotnet run --urls http://0.0.0.0:5000
dotnet publishBuild for productiondotnet publish -c Release
dotnet ef migrations addCreate migrationdotnet ef migrations add Initial
dotnet testRun unit testsdotnet test --logger "console"
dotnet watchHot reload developmentdotnet watch run
systemctl status dotnet-appCheck serviceShows if app is running
dotnet --infoShow .NET infoDisplays SDK/runtime details

๐Ÿ’ก Tips for Success

Follow these best practices for .NET on Linux success! ๐ŸŒŸ

๐Ÿš€ Performance Optimization

  • Use ReadyToRun compilation for faster startup
  • Enable tiered compilation
  • Configure appropriate GC mode
  • Use response caching where applicable

๐Ÿ”’ Security Best Practices

  • Never run as root user
  • Use HTTPS in production
  • Enable CORS carefully
  • Keep .NET runtime updated

๐Ÿ“Š Monitoring and Logging

  • Use structured logging (Serilog)
  • Implement health checks
  • Monitor with Application Insights
  • Set up proper log rotation

๐Ÿง Linux Integration

  • Follow Linux filesystem conventions
  • Use systemd for service management
  • Integrate with Linux logging
  • Respect Linux security model

๐Ÿ“ฆ Deployment Strategies

  • Use Docker for consistency
  • Implement CI/CD pipelines
  • Version your releases
  • Keep rollback strategies ready

โšก Development Workflow

  • Use VS Code with C# extension
  • Leverage dotnet watch for hot reload
  • Write unit tests from the start
  • Use async/await properly

๐Ÿ† What You Learned

Congratulations! Youโ€™ve mastered .NET Core on AlmaLinux! ๐ŸŽ‰ Hereโ€™s what you accomplished:

โœ… Installed .NET SDK and runtime on AlmaLinux successfully
โœ… Created ASP.NET Core applications from scratch
โœ… Configured Kestrel web server for production use
โœ… Set up systemd services for automatic startup
โœ… Implemented Nginx reverse proxy for production serving
โœ… Deployed with Docker for containerized environments
โœ… Integrated databases using Entity Framework Core
โœ… Solved deployment issues like a seasoned DevOps engineer

๐ŸŽฏ Why This Matters

.NET Core on Linux represents a fundamental shift in enterprise development - the walls between platforms have finally come down! ๐ŸŒŸ

This combination gives you the best of both worlds: Microsoftโ€™s powerful, productive framework running on Linuxโ€™s stable, cost-effective platform. You can now build high-performance applications that run anywhere, from on-premises servers to cloud containers, without vendor lock-in.

Whether youโ€™re migrating existing .NET applications to Linux, building cloud-native microservices, or starting fresh with cross-platform development, these skills position you at the forefront of modern application development. The future is cross-platform, and youโ€™re ready for it! ๐Ÿš€

Remember: .NET is no longer just for Windows developers. By embracing Linux, youโ€™re joining a growing community that values openness, performance, and choice. Keep exploring, keep building, and enjoy the freedom of true cross-platform development! โญ

Great job on completing this comprehensive .NET Core on Linux guide! Youโ€™re now ready to deploy enterprise .NET applications that run everywhere! ๐Ÿ™Œ