Create Azure Virtual Machine

Create Azure Linux Virtual Machine and make website running

While moving my blog to Azure Virtual Machine, I found some complexity just because of Linux virtual machine. As a ASP.NET geek, I am not that much of aware about Linux and its management commands. So, I have decided to write the blog on how to make my first Hello World website in Azure Linux Virtual Machine. I am also planning to write the blog on installing ASP.NET 5 into Linux Virtual Machine.

Create Linux Virtual Machine into Azure Cloud

The first step into making your website up and live is creating Linux Virtual Machine into Azure Cloud. Hence, I am logging with my Azure Account. There are two methods to create Virtual Machine into Azure. First one is creating Virtual Machine using Quick Create. Quick Create is used when you are creating only one Azure Machine. Another way to create Virtual Machine is using From Gallery, and it will be used when you are a need into creating multiple Azure Virtual Machine with some advance settings.

Sign into Azure portal and Click on New at the bottom left of Azure portal, then Click on COMPUTE -> VIRTUAL MACHINE -> QUICK CREATE as shown into the image.

Create Azure Virtual Machine
Create Azure Virtual Machine

After clicking on Quick Create, you will be prompted for entering some information about Virtual Machine like DNS name, Image for VM, Size for VM, Username, password, and region. I am going to creating VM with webstackdemo DNS name, and I am selecting Ubuntu Server 15.10 as Image name to create Linux Virtual Machine. Just enter all information and click on CREATE A VIRTUAL MACHINE button. You have to wait for some time after clicking on CREATE A VIRTUAL MACHINE while new server is up and running. On successful creation, your will be prompt like Successfully created virtual machine webstackdemo.

Login into Linux Cloud Virtual Machine
After successfully creating the virtual machine, you can look at endpoints of the virtual machine in Azure Portal. There will be default endpoint with named SSH having 22 as private and public port. You can change port at any time to secure your Virtual Machine. You can find SSH Details to connect or login into your machine in Dashboard tab. To login with your windows machine you need SSH client for windows like PuTTY.

Now, open PuTTY client and enter hostname and port detail from SSH Detail and click on open.

PuTTY detail to login into Azure
PuTTY detail to login into Azure

Now, PuTTY will prompt for credential. Login with the credential that you have created while creating your Azure Machine.

Installing Apache2, MySql, and PHP
To run large data driven application you need to have Apache2, MySql, and PHP installed into the virtual machine. So, you must have root access. Type following command to switch to root user.

sudo su

In order to install the latest version of services, your packages list from repository should be updated. There is apt-get command in Ubuntu server to update package list from repository server. So, type the following command to update package list

sudo apt-get update

After update modules, type following commands to install Apache2, MySql, and PHP

sudo apt-get install apache2
sudo apt-get install mysql-server
sudo apt-get install php5
sudo apt-get install php5-mysql

While Installing the MySql you will be prompted to enter the password for MySql. After successfully installing all above services you can type the following command to check that MySql services properly installed.
mysql -u root –p
It will prompt you to enter the password to log in.

Setup Virtual Host for Apache2
Create directory structure for your website and to set up virtual host into Apache2. Consider that you are going to setup into apache. In order to create the directory structure for type following command.

sudo mkdir -p /var/www/

Now, Create file into that html directory for your, you can use touch command to create file and nano to edit that file. You can also upload it using FTP, but for now, I am not going to cover that. Type following commands to create and edit index file.

cd /var/www/
sudo index.html
nano index.html

Type some HTML into index.html and save index.html file. Apache2 should have proper permission on that newly created directory. You can use chmod to give 755 permission on /var/www/ directory. Now, Its turn to create virtual host file and configure Apache2 to point that directory for Apache has default virtual host file called 000-default.conf. Copy that file with the new name like Type the following command of copying the file the as the new name.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/

Open that file and edit it to add configuration related to domain. After editing your host file, it should look like

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

After creating host file, you have to enable host file into Apache2. You can use a2ensite command of apache2 to enable that and then restart Apache2.

sudo a2ensite

The final step for your site to up and running is to add endpoints into Azure Cloud portal. Go to your virtual machine and click on ENDPOINTS. Click Add button from the bottom and Add HTTP Endpoint having 80 public port and private port for your site, you can also configure the endpoint to use HTTPS with 443 port.

Now you can run into your favorite browser to check that everything is working.

dnvm command

Installing ASP.NET 5 using DNVM (.NET Version Manager)

The starting point to start developing ASP.NET 5 application is how to install it. It is also important to be with the latest environment. There are two ways to install ASP.NET 5.

  1. Install ASP.NET 5 interactively
  2. Install ASP.NET 5 using DNVM Command (.NET Version Manager Command)

the easiest way to start is installing ASP.NET 5 is interactive. If you are interested into What is new in ASP.NET 5 beta8 read my previous blog post.

Install ASP.NET 5 interactively

An easy way to installing ASP.NET 5 interactive is as easy as you install any application in your window machine. You can download ASP.NET 5 beta8 installer from here. To develop ASP.NET 5 application, your should have Visual Studio 2015 installed from here. While installing Visual Studio 2015 you can also specify to install Microsoft Web Developer Tools or as specified earlier you can install standalone installer. The standalone installer is a just wizard, and you need to follow steps.

Install ASP.NET 5 using DNVM Command (.NET Version Manager Command)

To install ASP.NET 5 using DNVM, you need to have DNVM installed already. If you don’t have DNVM installed, you can install DNVM using the following command of PowerShell.

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString(''))}"

Alternatively, you can download PowerShell script dnvminstall.ps1 from GitHub.

After you install DNVM Command(.NET Version Manager Command) you can run dnvm on the command prompt. It will display you about dnvm command, version information, usages information, current feed settings, and commands of dnvm. If you are only interested into the version of DNVM Command, you can type dnvm version command.

about dnvm command
about dnvm command

While writing this blog post .NET Version Manager v1.0.0-rc2 has been released, but for now I am using .NET Version Manager v1.0.0-beta5, and I am going to demonstrate you about how to update dnvm command to latest version.
You can also update dnvm using dnvm update-self command

dnvm update-self command
dnvm update-self command

Run dnvm setup command to install the version manager into your profile directory. To skip configuring the user-level DNX_HOME and PATH environment variables use -SkipUserEnvironmentInstall optional switch with the dnvm setup.

The dnvm command is used to manage your .NET runtime. You can install a version of runtime, set default runtime, give the alias to installed runtime, list installed runtime, upgrade, and uninstall them. The Syntax to install .NET framework runtime is as follow

dnvm install [] [-a ] [-r ] [-OS ] [-Alias ] [-f] [-Proxy ] [-NoNative] [-Ngen] [-p] [-u] [-g]

To get a help on dnvm install command just type dnvm install. Alternatively, you can also type dnvm help to get help on particular command like dnvm help install, it will display the following output.

A version, nupkg path, or the string 'latest' must be provided.
dnvm install
  Installs a version of the runtime

  dnvm install [<VersionNuPkgOrAlias>] [-a <Architecture>] [-r <Runtime>] [-OS <OS>] [-Alias <Alias>] [-f] [-Proxy <Proxy>] [-NoNative] [-Ngen] [-p] [-u] [-g]

  <VersionNuPkgOrAlias> The version to install from the current channel, the path to a '.nupkg' file to install, 'latest' to
install the latest available version from the current channel, or an alias value to install an alternate
runtime or architecture flavor of the specified alias.
  -a                   The processor architecture of the runtime to install (default: x86)
  -r                   The runtime flavor to install (default: clr)
  -OS                  The operating system that the runtime targets (default: win)
  -Alias               Set alias <Alias> to the installed runtime
  -f                   Overwrite an existing runtime if it already exists
  -Proxy               Use the given address as a proxy when accessing remote server
  -NoNative            Skip generation of native images
  -Ngen                For CLR flavor only. Generate native images for runtime libraries on Desktop CLR to improve startup time. This option requires elevated privilege and will be automatically turned on if the script is running in administrative mode. To opt-out in administrative mode, use -NoNative switch.
  -p                   Make the installed runtime useable across all processes run by the current user
  -u                   Upgrade from the unstable dev feed. This will give you the latest development version of the runtime.
  -g                   Installs to configured global dnx file location (default: C:\ProgramData)

  A proxy can also be specified by using the 'http_proxy' environment variable

To uninstall .NET runtime type dnvm uninstall in Developer Command Prompt for VS2015.

You can use dnvm upgrade command to upgrade your .NET runtime. It will display progress on Developer command prompt like

dnvm upgrade command
dnvm upgrade command

You can use .NET Version Manager to install different versions of the DNX (.NET Execution Environment) to run and build the project. You can run the following command to install DNX for .NET core.

dnvm upgrade -r coreclr

You can also run the following command to install full .NET framework.

dnvm upgrade -r clr

To install x64 bit .NET framework use

dnvm upgrade -r coreclr -arch x64

After installing .NET framework, You can also view the installed framework. To view the installed. NET framework you can run following command in Developer Command Prompt for VS2015.

dnvm list

and, it will display Active Version, runtime, architecture, location, and alias of .NET framework as shown in the following image.

dnvm list command
dnvm list command

Alias is an easy way to refer .NET framework while executing dnvm commands. You can set alias name of .NET execution environment using following command.

dnvm alias full_default 1.0.0-beta8 -r clr -arch x86

and, to view and manage alias run

dnvm alias

to use or change .NET execution framework type following command

dnvm use full_default