Install ASP.NET Core on Ubuntu Linux and Configure it to Serve a Web Application
Download Ubuntu server 18.04 from here and install it.
Install ASP.NET Core
To install ASP.NET Core 2.2 on the Ubuntu 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-2.2
To install ASP.NET Core 3.0 on the Ubuntu 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.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 (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 sudo reboot
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 touch app.conf 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:
