Wednesday, February 25, 2015

[Quick Tips]: How to Run ASP.Net on Linux

How to Run ASP.Net on Linux

 

Recently, we have heard many important announcements from Microsoft. As an initiative towards openness and the open source community Microsoft made the .NET Core open source, including the runtime as well as the framework libraries.

vNext can run in a non-Microsoft environment. Let us discuss how to install and run ASP.NET vNext (Alpha 3) on Ubuntu Linux.

First of all we need a Linux environment installed on a physical or virtual box. I am using an Oracle VM virtualbox for demo purposes. I have installed Ubuntu using it.

Let us start

Ubuntu 

installed Ubuntu

We are ready with the basic installation of Linux. We need to set up a network related connection.

basic installation of Linux

connection

Let us start with the Mono installation as in the following:

sudo apt-get install build-essential wget: mono-3.8.0.
            tar -xvf mono-3.8.0.tar.bz2 cd mono-3.8.0/
            ./configure --prefix=/usr/local


make sudo make install

make sudo make install

The .NET Framework on Windows uses the Windows Certificates store to check whether to accept an SSL certificate from a remote site. In Mono, there is no Windows Certificate store. It has its own store. By default, it is empty and we need to manage the entries ourselves.
  1. CERTMGR=/usr/local/bin/certmgr sudo $CERTMGR -ssl -m https://go.microsoft.com sudo $CERTMGR -ssl -m https://nugetgallery.blob.core.windows.net sudo $CERTMGR -ssl -m https://nuget.org sudo $CERTMGR -ssl -m https://www.myget.org/F/aspnetvnext/  mozroots --import --sync  
Project “K”
This K is a pack of tools / assemblies and command line utilities that help to compile and host / run the new ASP.NET 5 (and console application). K creates an abstraction between the new ASP.NET framework and the .NET framework, with which ASP.NET 5 can be developed, compiled and hosted on Windows, Linux and Mac (using the .NET framework on Windows and Mono runtime on Mac / Linux).

Project K is a pack of the following 4 main components: 
  • KRE: K Runtime Environment
  • KVM: K Version Manager
  • KPM: K Package Manager
  • K / KLR: K runtime / K language runtime
The following are the commands to install project “K” in a Linux environment.

sudo apt-get install curl:

            curl -ssl https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh && source ~/.kre/kvm/kvm.sh

            kvm upgrade (To download the full dot net CLR)


Currently we need a couple of dependencies to run the .Net framework. 

To install libuv we need to resolve one more dependency using:

sudo apt-get install gyp

To download libuv wget.

            tar -xvf libuv-v1.0.0-rc1.tar.gz
            cd libuv-v1.0.0-rc1/
            ./gyp_uv.py -f make -Duv_library=shared_library

            make -C out

            sudo cp out/Debug/lib.target/libuv.so /usr/lib/libuv.so.1.0.0-rc1

            cd ..

            sudo ln -s libuv.so.1.0.0-rc1 /usr/lib/libuv.so.1 


To download sample files from github wget:

            unzime master.zip

To run console application

            cd Home-master/samples/ConsoleApp

            kpm restore

            k run


k run

To run MVC.NET application
            cd Home-master/samples/HelloMvc
            kpm restore
            k kestrel


Kestrel is a new cross-platform OWIN web server for ASP.NET. By default, Kestrel runs on port 5004, thus opening our browser of choice with http://localhost:5004 gives us the desired result:

desired

Reference Link:

 

No comments: