Host a .net app on Linux with CloudPanel 2

Here is a step by step guide to deploy and serve .net web application on Debian ( ubuntu also ok) and control panel solution as Cloud Panel 2

Firstly you need and up and running CloudPanel 2, You can use Digital Ocean and simply set up a new droplet (VPS server) with CloudPanel from marketplace.

Or install Cloud Panel 2 manually using these steps here:

In this senario my app name is NA.Api, you can rename NA.Api in following scripts

  1. Install github cli
  2. Install dotnet SDK
  3. Clone your code, I use /home/repos/ foder; gh repo clone SolidAppers/NA.Api
  4. Write deploy script;
    cd /home

    Paste following script;

    echo "NA.Api Deployment"
    cd /home/repos/NA.Api/
    echo "Sync repo"
    gh repo sync
    echo "Stop service"
    systemctl stop  NA.Api.service
    echo "Publishing ..."
    dotnet publish -c Release -o /home/deploy/NA.Api/
    echo "Starting service"
    systemctl start  NA.Api.service
    echo "Done!"
  5. Add service file
    $ cd /etc/systemd/system
    $ nano NA.Api.service

    Paste following script;

    Description=NA.Api App
    ExecStart=/usr/bin/dotnet /home/deploy/NA.Api/NA.Api.dll --urls "https://localhost:5601"
    # Restart service after 10 seconds if the dotnet service crashes:
  6. Automatically get it to start on boot: $ systemctl enable NA.Api.service
  7. We can now start the service: $ systemctl start NA.Api.service
  8. And automatically get it to start on boot: $ systemctl enable NA.Api.service
  9. That’s it! run the deploy script bash
  10. Lastly add a site on CloudPanel with Reverse proxy