Here is a step by step guide to deploy and serve .net7 web app on Debian ( ubuntu also ok) and hosting 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 with CloudPanel from marketplace.

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 And automatically get it to start on boot: $ systemctl enable NA.Api.service
  8. That’s it! run the deploy script bash
  9. Lastly add a site on CloudPanel with Reverse proxy

More Articles


Shere Your Opinion
Textile help