Shortly after the release of ASP.NET Core 2.0 I decided to re write the MVC blog engine I had been working on with the intention of seeing if I could "easily" host it on a Linux VPS. Being an ASP.NET developer, all my current/past projects were hosted on IIS on a Windows server and I was totally unfamiliar with the Linux CLI and using SSH. To be fair, the closest I had come to provisioning a website on Linux was through cPanel on our locally hosted Linux VPS's which took all the guess work out of it. I now built the site using ASP.NET Core 2.0, using Bootstrap for the front end layout, Entity Framework (using the repository pattern) for the backend and SQLite as the database provider knowing that it is fully supported across all server platforms.
Next step is to find a reliable and cheap Linux VPS to test this out on. After scouring the interwebs I had two options available to me, the first being Linode and the second being Digital Ocean. I went with Digital Ocean as they had tons of step by step tutorials on setting up, securing/hardening and installing all the most common software on their Droplets (VPS’s). As I was given a referral link like the one above , I received $10 free credit when signing up. The sign up process was super simple and provisioning the Droplet just as easy. First you chose an image, I went for Ubuntu 16.04, then you can pick the size of the droplet, if you want extra block storage and then the datacenter location for the droplet. As London was the closest location to me, I went for that option. Afterwards you can pick some extra options like ipv6 and backups etc., then SSH keys and lastly the name for your droplet. They have a default naming convention for the Droplets which uses the distro name, the size and the location and looks something like this.
Clicking the “Create” button starts the provisioning process which for my Droplet took about a minute. If you didn't chose an SSH key during the setup process then you will receive an email with the login credentials and IP address for your new droplet. After this you can use your favorite SSH client to connect to the server with your login credentials. I used the version that can be enabled in the fall creators update of Windows 10.
Once logged in, the first thing you will be asked to do is change your password (It is also suggested to create a new user with sudo privileges instead of using root). After this is done its would be best to check for any updates. From here on out I will include the CLI commands I used, these are all for Ubuntu 16.04.
Step 1 – Check for any updates
Updating the package list
sudo apt-get update
Update packages to their latest versions
sudo apt-get upgrade
Step 2 – Install .Net Core
Next, go to https://www.microsoft.com/net and follow the instructions there to install .NET Core. There are multiple distros supported so you shouldn't have any trouble finding the right one for you. I followed the Ubuntu instructions. Once installed, you can test if everything installed correctly by running
The response should look something like:
In the next part of this post I will go into details on how to setup SFTP so you can transfer your app’s files to the server, NGINX for acting as a reverse proxy for Kestrel as you don't really want to expose Kestrel to the outside world and then setting up a service like Supervisor to ensure your app stays running. In later posts I will also include details on setting up some essential security measures and how to install an SSL certificate using Lets Encrypt.
If you have any questions, please feel free to post them in the comments below.