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
- VirtualHost *:80>
- ServerName www.DOMAIN.COM
- ProxyPreserveHost On
- ProxyPass / http://127.0.0.1:5000/
- ProxyPassReverse / http://127.0.0.1:5000/
- RewriteEngine on
- RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
- RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
- RewriteRule /(.*) ws://127.0.0.1:5000/$1 [P]
- ErrorLog /var/log/apache2/netcore-error.log
- CustomLog /var/log/apache2/netcore-access.log common
- </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}