PROWAREtech

articles » current » information-technology » linux » setup-and-configure » asp-net-core

Install ASP.NET Core on Ubuntu Linux

Install ASP.NET Core 3.1 and ASP.NET Core 6.0 on Ubuntu Linux and configure it to serve a Web Application.

See also: The Easy Way to Distribute on Linux & Install ASP.NET Core 3.0 on Linux ARM 32-bit (Raspberry Pi) and Configure it to Serve a Web Application

Download Ubuntu server from here and install it.

Install ASP.NET Core

To install ASP.NET Core 3.1 on the Ubuntu 18.04 Linux machine. Issue these commands from a directory with write permissions:

wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo add-apt-repository universe
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install aspnetcore-runtime-3.1

To install ASP.NET Core 6.0 on the Ubuntu 20.04 Linux machine. Issue these commands from a directory with write permissions:

wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo add-apt-repository universe
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install aspnetcore-runtime-6.0

Install and Configure Apache Web Server

NOTE: skip this step by changing the port the ASP.NET Core Kestrel server is listening on to 80 or 443 (from 5000).

Issue these commands to install and configure Apache as a proxy.

sudo apt-get update
sudo apt-get install apache2
sudo a2enmod proxy proxy_http proxy_html
sudo nano /etc/apache2/sites-enabled/000-default.conf

With a hashtag (#), comment out all the lines until just these remain or have been added:

NANO Edit 000-default.conf:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:5000/
ProxyPassReverse / http://0.0.0.0:5000/
</VirtualHost>

Install and Configure Samba Server

Install and configure Samba with these commands:

sudo apt-get install samba samba-common-bin
sudo nano /etc/samba/smb.conf

Create the new share [www] in this file.

NANO Edit smb.conf:
[www]
path=/var/www
writable=yes
browseable=yes
only guest=no
create mask=0777
directory mask=0777
public=yes
guest ok=yes

Edit access rights for /var/www and reboot the Linux server.

sudo chmod 0777 /var/www

Create a Web Application

Create an ASP.NET Core Web Application (MVC) in Visual Studio. Call it "app" for the purposes of this tutorial. Publish it as File System for Linux-x64 and Framework-Dependent.

Copy the published files to the Linux machine using its Windows share www. Copy the files into a directory named app.

Install and Configure Supervisor

Supervisor will automatically run the "app" everytime the machine starts. Issue these commands to install and configure Supervisor:

sudo apt-get install supervisor
cd /etc/supervisor/conf.d
sudo nano app.conf

Enter this text into the file.

NANO Edit app.conf:
[program:app]
command=/usr/bin/dotnet /var/www/app/app.dll
directory=/var/www/app
autostart=true
autorestart=true
environment=ASPNETCORE_ENVIRONMENT=Production
user=www-data
stopsignal=INT

To stop the "app" so that new files can be copied to the Linux server, issue this command:

sudo service supervisor stop

To start the "app" after new files have been copied over, issue this command:

sudo service supervisor start

Reboot the Ubuntu server and access its IP address from a browser and you will see this:


PROWAREtech

Hello there! How can I help you today?
Ask any question

PROWAREtech

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
ACCEPT REJECT