Run dotnet in Ubuntu 20.04 LTS and aaPanel
Posted on 02 January 2024 20:33 GMT +00:00
Run Umbraco in Ubuntu
Follow the steps outlined to achieve this:
Install aaPanel
Optional but useful for maintenance:
The install script will complete within a few minutes and will install the hosting panel giving you valuable tools to maintain your sites.
wget -O install.sh http://www.aapanel.com/script/install-ubuntu_6.0_en.sh && sudo bash install.sh
Add Microsoft Install Manager Repository if not found
# Get Ubuntu version
declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)
# Download Microsoft signing key and repository
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
# Install Microsoft signing key and repository
sudo dpkg -i packages-microsoft-prod.deb
# Clean up
rm packages-microsoft-prod.deb
# Update packages
sudo apt update
Install dotnet 6
sudo apt-get update && sudo apt-get install -y apt-transport-https aspnetcore-runtime-6.0
Install dotnet 7
sudo apt-get update && sudo apt-get install -y apt-transport-https aspnetcore-runtime-7.0
Install dotnet 8
sudo apt-get update && sudo apt-get install -y apt-transport-https aspnetcore-runtime-8.0
Create the service file
sudo nano /etc/systemd/system/kestrel-helloapp.service
The following example is a service file for the app:
[Unit]
Description=Example .NET Web API App running on Linux
[Service]
WorkingDirectory=/var/www/helloapp
ExecStart=/usr/bin/dotnet /var/www/helloapp/helloapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Enable the service
sudo systemctl enable kestrel-helloapp.service
sudo systemctl start kestrel-helloapp.service
sudo systemctl status kestrel-helloapp.service
Create the dotnet site in aaPanel
And make sure you set the reverse proxy to the port you configured for the dotnet app (default is 5001)
At this point, you can already deploy your website and browse to it.
If you are going to use MSSQL with Ubuntu, make sure to install it following these steps:
IMPORTANT: you must have an Ubuntu 20.04 machine with at least 2 GB of memory
Import the public repository GPG keys:
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
Register the SQL Server Ubuntu repository:
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2022.list)"
Run the following commands to install SQL Server:
sudo apt-get update
sudo apt-get install -y mssql-server
After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition. As a reminder, the following SQL Server editions are freely licensed: Evaluation, Developer, and Express.
sudo /opt/mssql/bin/mssql-conf setup
Once the configuration is done, verify that the service is running:
systemctl status mssql-server --no-pager
Allow external connections through the firewall
sudo ufw allow 1433
Once you're done deploying, secure the server with these commands (optional for 22)
ufw deny 1433
ufw deny 22
ufw deny 21
ufw deny 20