How to install .net core in Linux?

As we all know .NET core is cross-platform but it would be hard to publish a .NET core project on Linux OS. Do not worry, KLCWEB has a solution and guides to install .net core to Linux OS. Let’s install.net core in Linux OS.

1.) Install required component

  • sudo apt-get update
  • sudo apt-get install apt-transport-https
  • sudo apt-get update
  • sudo apt-get install dotnet-sdk-3.1
  • sudo apt-get install dotnet-runtime-3.1
  • sudo apt-get install aspnetcore-runtime-3.1

2.) Configure Apache server

Once You did install all the .NET core required components for Linux then, configure the Apache server to run the .NET core on Linux OS.

  • sudo apt-get install apache2
  • sudo a2enmod proxy proxy_http proxy_html proxy_wstunnel
  • sudo a2enmod rewrite
Now, you need to make configuration file for proxy on Apache

> sudo nano /etc/apache2/conf-enabled/netcore.conf

  1. VirtualHost *:80>  
  2.    ServerName www.DOMAIN.COM  
  3.    ProxyPreserveHost On  
  4.    ProxyPass / http://127.0.0.1:5000/  
  5.    ProxyPassReverse / http://127.0.0.1:5000/  
  6.    RewriteEngine on  
  7.    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]  
  8.    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]  
  9.    RewriteRule /(.*) ws://127.0.0.1:5000/$1 [P]  
  10.    ErrorLog /var/log/apache2/netcore-error.log  
  11.    CustomLog /var/log/apache2/netcore-access.log common  
  12. </VirtualHost>  

Paste this code to config file of Apache server, ensure that you will replace www.domain.com > your real domain name.

3.) Restart Apache server

  • sudo service apache2 restart
  • sudo apachectl configtest

4.) Start .NET service.

You need to move your all projects files to specific path using the below command.

sudo cp -a ~/release/ /var/netcore/

> Now, Create a service file for you .NET core project.

sudo nano /etc/systemd/system/ServiceFile.service

Now, restart your server using the below code.
  • sudo systemctl enable {Service Name}
  • sudo systemctl start {Service Name}
Tagged :

Leave a Reply

Your email address will not be published. Required fields are marked *