MacakM
MacakM

Reputation: 1820

How to run already developed ASP.NET Core app on Ubuntu?

What is the easiest way to run my existing ASP.NET Core application on Ubuntu? I have found this: https://learn.microsoft.com/en-us/aspnet/core/publishing/linuxproduction but I am stuck on this: enter image description here

I have published the application and copied it to my Ubuntu, but I have no idea how can I "run the app". Any help will be really appreciated.

Upvotes: 4

Views: 1168

Answers (1)

DavidG
DavidG

Reputation: 118937

It's really as simple as executing:

dotnet path/to/your/application.dll

However, for a website you really want to manage that with some sort of init system. The doc file you link to tells you how to start your application using Systemd.

  1. Create a service definition file e.g. /etc/systemd/system/myapp.service
  2. Edit the file to look like this, replacing the relevant parts where necessary:

    [Unit]
    Description=Example .NET Web API Application running on Ubuntu
    
    [Service]
    WorkingDirectory=/var/path/to/your/app
    ExecStart=/usr/bin/dotnet /var/path/to/your/app/hellomvc.dll
    Restart=always
    RestartSec=10  # Restart service after 10 seconds if dotnet service crashes
    SyslogIdentifier=dotnet-example
    User=www-data
    Environment=ASPNETCORE_ENVIRONMENT=Production 
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable the service like this:

    systemctl enable myapp.service
    
  4. Start the service:

    systemctl start myapp.service
    
  5. Check if your service is running:

    systemctl status myapp.service
    

If you have another init system, the instructions will of course be quite different.

Note: This only starts the app running on your machine. If you intend to serve it to the public, then it is highly recommended that you use a proxy such as Nginx as Microsoft has not yet certified Kestrel as an edge server.

Upvotes: 5

Related Questions