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
- Install github cli https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt
- Install dotnet SDK https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian
- Clone your code, I use /home/repos/ foder;
gh repo clone SolidAppers/NA.Api
- 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!"
- 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
-
Automatically get it to start on boot:
$ systemctl enable NA.Api.service
- We can now start the service: $ systemctl start NA.Api.service And automatically get it to start on boot: $ systemctl enable NA.Api.service
-
That’s it!
run the deploy script
bash NA.Api.sh
- 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/