Host ASP.NET Core 2.1 application on Ubuntu Server 18.04

Host ASP.NET Core 2.1 application on Ubuntu Server 18.04

To understand and apply this, first see:

The tutorial from above is pretty straightforward, but is for Ubuntu Server 16.04. In the following, i will show you how to bypass the problems when hosting ASP.NET Core 2.1 application on Ubuntu Server 18.04.

The first problem is installing the SDK, for Ubuntu Server 18.04 use:

shell> curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
shell> sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
shell> sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic main" > /etc/apt/sources.list.d/dotnetdev.list'
shell> wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
shell> sudo dpkg -i packages-microsoft-prod.deb
shell> sudo apt-get install apt-transport-https
shell> sudo apt-get update
shell> sudo apt-get install dotnet-sdk-2.1.3

The 2nd problem are the rights on the application directory, use:

shell> sudo chmod -R 1744 /var/aspnetcore/hellomvc

The 3th problem are the rights on the service definition file, use:

shell> sudo chown root:root /etc/systemd/system/kestrel-hellomvc.service
shell> sudo chmod +x /etc/systemd/system/kestrel-hellomvc.service

The 4th problem is that the "www-data" user is not created automatically, only the "www-data" group, use:

shell> sudo adduser xxxxxxx www-data

to add the admin user to the "www-data" group and change the service definition file to:

[Unit]
Description=Kestrel service running .NET Core

[Service]
WorkingDirectory=/var/aspnetcore/hellomvc
ExecStart=/usr/bin/dotnet /var/aspnetcore/hellomvc/hellomvc.dll
Restart=always
RestartSec=10 # resteart after 10 sec if crashed
SyslogIdentifier=dotnet-kestrel
Group=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

Enjoy (ง°ل͜°)ง

Comments

Popular Posts