Zobi Web Solutions is a well-known name in Blazor App Development Company. We have successfully completed multiple projects and our experienced and dedicated developers served the best results for this technology and have been given some promising results. Get a free consultation today to develop a Blazor Application on the Linux platform.
You want to try the Blazor, on your Linux machine. Well, you are lucky. One of the goals of the Asp.Net core is being cross-platform. so in this blog, we will see how “cross-platform” is with Blazor Microsoft’s hot new front-end development project.
For setting up Blazor app on Linux We can follow the given steps.
Setup .net core
Register Microsoft key and feed :
Before installing .NET, you’ll need to :
- Register the Microsoft key.
- Register the product repository.
- Install required dependencies.
This only needs to be done once per machine.
Open a terminal and run the following commands.
wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
Install the .NET Core SDK :
Update the products available for installation, then install the .NET Core SDK. In your terminal, run the following commands.
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-sdk-3.1
Install the ASP.NET Core runtime :
Update the products available for installation, then install the ASP.NET Core runtime. In your terminal, run the following commands.
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install aspnetcore-runtime-3.1
Install the .NET Core runtime :
Update the products available for installation, then install the .NET Core runtime. In your terminal, run the following commands.
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install dotnet-runtime-3.1
Publish and copy over the app :
Check app running success fully on local machine.
Remove https://localhost:5001 (if present) from the applicationUrl property in the Properties/launchSettings.json file.
Run dotnet publish from the development environment to package an app into a directory (for example, bin/Release/<target_framework_moniker>/publish) that can run on the server:
dotnetpublish –configuration Release
Copy the ASP.NET Core app to the server using a tool that integrates into the organization’s workflow (for example, SCP, SFTP). It’s common to locate web apps under the var directory (for example, var/www/demoapp).
Test the app :
- From the command line, run the app: dotnet<app_assembly>.dll.
- In a browser, navigate to http://<serveraddress>:<port>to verify the app works on Linux locally.
Install Nginx :
sudo apt-get update
sudo apt-get install nginx
sudo service nginx start
Verify a browser displays the default landing page for Nginx. The landing page is reachable at
http://<server_IP_address>/index.nginx-debian.html.
Configure Nginx :
To configure Nginx as a reverse proxy to forward requests to your ASP.NET Core app, modify /etc/nginx/sites-available/default. Open it in a text editor, and replace the contents with the following:
server_name example.com *.example.com;location /
{
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Once the Nginx configuration is established, run sudo nginx -t to verify the syntax of the configuration files. If the configuration file test is successful, force Nginx to pick up the changes by running sudo nginx -s reload.
To directly run the app on the server :
- Navigate to the app’s directory.
- Run the app: dotnet<app_assembly.dll>, where dllis the assembly file name of the app.
When done testing the app, shut the app down with ctrl + c at the command prompt.
Monitor the app :
The server is setup to forward requests made to http://<serveraddress>:80 on to the ASP.NET Core app running on Kestrel at http://127.0.0.1:5000. However, Nginx isn’t set up to manage the Kestrel process. systemd can be used to create a service file to start and monitor the underlying web app. systemd is an init system that provides many powerful features for starting, stopping, and managing processes.
Create the service file :
Create the service definition file:
sudo nano /etc/systemd/system/kestrel-newapp.service
The following is an example service file for the app:
[Unit]Description=Example .NET Web API App running on Ubuntu
[Service]
WorkingDirectory=/var/www/demoapp
ExecStart=/usr/bin/dotnet /var/www/demoapp/newapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Save the file and enable the service.
sudo systemctl enable kestrel-newapp.service
Start the service and verify that it’s running.
sudo systemctl start kestrel-newapp.service
sudo systemctl status kestrel-newapp.service
- kestrel-newapp.service – Example .NET Web API App running on Ubuntu
Loaded: loaded (/etc/systemd/system/kestrel-newapp.service; enabled)
Active: active (running) since Thu 2016-10-18 04:09:35 NZDT; 35s ago
Main PID: 9021 (dotnet)
CGroup: /system.slice/kestrel-newapp.service
└─9021 /usr/local/bin/dotnet /var/www/demoapp/newapp.dll
Conclusion
This is how you can deploy your Blazor application on Linux operating system which is totally open-source. If you have any queries regarding this, you can contact Zobi Web Solutions, which is one of the earliest adopters of this technology and a prominent web and mobile app development company.