To use the following procedure you first need to have a Microsoft Azure account. The supported Linux version is Ubuntu snappy.
Login to the Microsoft Azure to access your Azure account. In this article I'm using the newly launched Azure portal that has blades to support multiview in one window. We'll start with creating a new Linux VM on Azure and then configuring it for ASP.Net vNext hosting.
Step 1: Click on New and select Ubuntu.
Step 2: Specify the required details for the new Linux VM details.
If all the details are correct and filled in then the Create button will be enabled. Click on Create and then the VM will start initializing and allocating respective resources for the Linux VM. This process will take 10-15 minutes to finish.
You'll get a similar view of the new Linux machine. If you click on Settings then Properties then you can get the DomainName with other details. This domain name will be used as the machine name to connect via remote client.
Step 3: Once the VM is created, the next step would be to connect with the Linux VM. If you're on Windows you can use the Putty tool to connect to the server console. Here are a few quick steps to connect to the Linux VM.
- Launch the Putty tool and enter the domain name of the new machine.
- Once you click open, if the domain name is valid a command window will open asking for username and password. Enter the details and the Linux machine will be connected and ready to receive the commands.
Step 4: Now you're connected with the Linux VM. To get the server ready we now need to install the components to have the .Net core installed on the server. For the Linux machine the .Net core is supplied with in MONO project from Xamarin and contributors. To check if Mono is installed run the following command.
Code
MONO --VERSION
Of cource the Mono is not installed on the server so we need to install it. Run the following commands to install Mono.
Note: You can try downloading the mono-runtime with the suggested command. But I'm not sure if that will provide the fully featured Mono on the Linux. I haven't tested it.
Downloading required tools
Code:
SUDO APT-GET INSTALL MAKE
SUDO APT-GET INSTALL GIT AUTOCONF LIBTOOL AUTOMAKE BUILD-ESSENTIAL MONO-DEVEL GETTEXT ZIP MONO-COMPLETE UNZIP
Download Mono and compile it. Run the following command to get the latest Mono version ready to Install.
PREFIX=/USR/LOCAL
PATH=$PREFIX/BIN:$PATH
VERSION=3.10.0
WGET HTTP://DOWNLOAD.MONO-PROJECT.COM/SOURCES/MONO/MONO-$VERSION.TAR.BZ2
TAR -XJVF MONO-$VERSION.TAR.BZ2
CD MONO-$VERSION
./AUTOGEN.SH --PREFIX=$PREFIX
MAKE
MAKE INSTALL
This procedure will take more than 30 minutes for the downloading, compiling and installing of Mono.
Now we need to install a few more components, like NPM, Git, KVM and K Runtime with Kestrel server. Before downloading and installing these components a few SSL certificates must be added to the certificate store of the machine. With this step the downloading of the required Nugets will not take place and will provide a missing certificate error.
Installing certificates
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/
To avoid the few certificates that falls under the untrusted certificates run the following command:
Installing KVM on server
Run the following commands to download and install Kvm.
curl -sSL https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh & source ~/.kre/kvm/kvm.sh
source /home/punitganshani/.kre/kvm/kvm.sh
kvm upgrade
Now, check the Mono version again as in the following:
Mono –Version
Note: If you don't see the version 3.10.0 of Mono then repeat the preceding procedure for installing the Kvm again. Because only this version is supported for the Kestrel server that hosts the ASP.Net vNext application.
Now to verify if the K Runtime is installed Run “k”.
Installing Kestrel server
To install the Kestrel server run the following commands:
Now we need a sample application so that we can test the installed components. We'll be using the ASP.Net starter application from Github. Run the following command:
Navigate to the following directory hierarchy:
Home -> samples -> HelloWeb
After navigating run the following command:
If there's no error in restoring the Nuget packages and building the application then the application is ready to be hosted. Run the following command to host the application in the Kestrel server:
You might get the following error:
System.NullReferenceException: Object reference not set to an instance of an object at Microsoft.AspNet.Server.Kestrel.Networking.<strong>Libuv</strong>.loop_size () [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Server.Kestrel.Networking.UvLoopHandle.Init (Microsoft.AspNet.Server.Kestrel.Networking.Libuv uv) [0x00000] in <filename unknown>:0 at Microsoft.AspNet.Server.Kestrel.KestrelThread.ThreadStart (System.Object parameter) [0x00000] in <filename unknown>:0
For Web Applications, we need KestrelHttpServer that is built on the libuv library.
WGET HTTP://DIST.LIBUV.ORG/DIST/V1.0.0-RC1/LIBUV-V1.0.0-RC1.TAR.GZ
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
SUDO LN -S LIBUV.SO.1.0.0-RC1 /USR/LIB/LIBUV.SO.1
Now run the following command again:
K KESTREL
It should say “Started” at this time.
The application is hosted at localhost:5004 (default port for Kestrel server). It can be changed from the project.config file.
Exposing hosted website
Now to expose the hosted site to the external world the last thing is to add an Endpoint on your Linux machine via Azure portal. To add the Endpoint go back to the Azure portal select the Linux VM then click Settings -> Endpoints -> Add.
Fill in the details. If all the endpoint details are valid, click OK. Now your machine is ready to show the hosted ASP.Net vNext starter application to the external world.
Now open browser on the local machine. Go to http://<domain name>
For example:
http://testlinux1234z.cloudapp.net/