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 https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt
  2. Install dotnet SDK https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian
  3. Clone your code, I use /home/repos/ foder; gh repo clone SolidAppers/NA.Api
  4. Write deploy script;
    cd /home
    nano NA.Api.sh
    

    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;

    [Unit]
    Description=NA.Api App
    
    [Service]
    WorkingDirectory=/home/deploy/NA.Api
    ExecStart=/usr/bin/dotnet /home/deploy/NA.Api/NA.Api.dll --urls "https://localhost:5601"
    Restart=always
    # Restart service after 10 seconds if the dotnet service crashes:
    RestartSec=10
    KillSignal=SIGINT
    SyslogIdentifier=NAapi-app
    User=root
    Environment=ASPNETCORE_ENVIRONMENT=Production
    Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
    
    [Install]
    WantedBy=multi-user.target
    
  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 NA.Api.sh
  9. Lastly add a site on CloudPanel with Reverse proxy https://www.cloudpanel.io/blog/cloudpanel-2-2-1-release-reverse-proxy-support-and-new-languages/

More Articles

Comments

Shere Your Opinion
Textile help