Deploy .Net Core App on a Linux Host like 1and1

It’s an exciting time for C-Sharpers, we are no longer doomed to a world of expensive hosting solutions – seriously, Azure (although great) was costing me a fortune. In this tutorial I’m going to show you how to deploy a net core app on a linux host, such as those provided by 1and1 and other linux based host providers.

With 1and1 I have a virtual cloud server subscription, it costs me around £14 per month but I currently have around 20 sites running on it with plenty of room for more. It would cost quite a bit to host that on Azure. You can use any linux hosting provider you wish but you must have root access and be able to connect with SSH.

Before we get into the detail, I have also provided this article in video form for those of you who do not want to read my ramblings. It can be found here. You can listen to them instead!

Install .Net Core on a Linux Host

Ok so let’s get into it. I haven’t really done anything magic or clever. I referenced the Microsoft documentation on how to install .netcore  on my linux server. The link for this is here. On the page there is a drop down to select the different flavours of Linux. So for CentOS (which is what I have installed) connect to your server using SSH and then type the following commands.

Then.

And then.

Followed by.

And finally.

Create  a New Website With Plesk

Once you have .Net Core installed log into Plesk* and create a new website.
*Plesk is a tool for managing your server, if you do not have Plesk you should have some other graphical management tool

Create a new doamin to host your .net core app

Fill out the details as normal, as far as I am aware there is no special requirements at this stage. You can even use Let’s Encrypt to create an SSL certificate for your site. Once your new website is created you need to go to the Apache & Nginx settings.

Apache settings for .net core app hosting on linux

We are interested in these two options

apache settings for hosting dotnetcore apps

In both of those we are going to add the following

IMPORTANT: Please make sure you change the server name to the domain name that you want!

This sets up Apache to forward requests to your running .net app. But that’s the problem, you would actually have to go into the command line and run the app using the dotnet run command. We don’t want to have to do that!

Configure Apache to manage the Kestrel process

First you will need to create a service definition file.

then you need to define the service in the file just created. Like this

Read read the values and make sure they are correct for your environment and app name. Next you need to enable the service.

And finally start and check the service

And that’s it!. You have now configured a net core app on a linux host.

Much of the technical content of this article has been taken from Microsoft articles, one of which is this one. I would highly recommend that you read it as it goes into other issues including firewall settings.

A final note on hosting

There are a lot of providers out there, some good, some not so good. I have been using 1and1 for around 10 years and I have found them to be excellent and great value for money. I currently operate 2 virtual servers hosted with them. In the 10 years that I have been with 1and1, I have experienced two problems, both of my own creation, but they solved the issues within an hour each time. If you rely on the web for your business then I can’t recommend them highly enough. And especially now you can host net core app on a linux, I’ll definitely be staying with them.
1&1 Hosting: all products and services


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.