If you need to deploy the whole project in a new server, you can follow this procedure. If your application is deployed with git and you need to just update the project, please read this.
- Create a new user in your CentOS
- Install Required Packages
- Configure Application
- Configure Supervisor
- Configure Application with Supervisor for making the app Up and running with log management
- Add the application ports in the firewall allowed port
- Viewing the server Log
ssh root@<ip_address>Then give password.
adduser [username]
passwd [username]
usermod -aG wheel [username]
exitThen login again with new created user-
ssh [username]@<ip_address>- Update All existing Packages for security-
sudo dnf update -ysudo dnf update kernel -y && sudo dnf install epel-release -y && sudo dnf upgrade -y
cat /etc/redhat-releaseInstall some required packages for deploy-
sudo dnf install nano net-tools git wget -y- Install all required packages-
sudo dnf install dotnet-sdk-3.1 aspnetcore-runtime-3.1 dotnet-runtime-3.1 supervisor -y
dotnet tool install --global dotnet-efsudo rpm -Uvh https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm- Clone the project into
userdirectory-
cd ~ && git clone https://github.com/BCC-CA/Asp.NetCore_3.1-PostGRE_Signing-ASP.git asp && cd ./asp && git config pull.ff only- Configure Database-
cp appsettings.json.example appsettings.json && nano appsettings.jsonThen edit the ConnectionStrings->DefaultConnection section for database and edit the SmtpSettings section for mail settings. A demo Gmail configuration is given in SmtpSettings_ part.
3. Migrate the database-
dotnet ef database updateThis command will create all table in the database and migrate seed data in the database. If running this command is not working, then creating the database from other source can also work.
4. Deploy the application to the PublishedWebApp folder in user folder, please provide this command-
dotnet publish -c Release -o /home/abrar/PublishedWebAppFor the first time, it will take some time as it will download all the server side and client side libraries.
After the deploy command done, you will get your deployable files inside /home/abrar/PublishedWebApp folder. In the folder, there will be a .dll file named <your_application_name>.dll in the folder. Lets the application name is SinedXmlVelidator, so we will get SinedXmlVelidator.dll file inside the PublishedWebApp folder. We need to run the application with a task runner. We are using supervisor for that, so we need to configure supervisor for running the application.
To make an app running with supervisor and configurable with .conf file in /etc/supervisord.d/ directory, we need to configure supervisor like this-
sudo cp /etc/supervisord.conf /etc/supervisord.conf.bak && sudo vi /etc/supervisord.confThen find the last line (shortcut can be files = supervisord.d/*.ini):
files = supervisord.d/*.iniAnd replace it with (keyboard key may be i)-
files = supervisord.d/*.confThen save the file with-
:wq!Before creating the service, please check the compatiblity by running the application through command line first-
dotnet run --urls "http://*:80;https://*:443"If error occures, then try allowing port 80 and 443 in firewall by running this commands and try again-
# Generate self signed SSL Certificate
sudo security set-key-partition-list -D localhost -S unsigned:,teamid:UBF8T346G9
dotnet dev-certs https
# Enable Firewall
sudo systemctl enable firewalld && sudo systemctl start firewalld && sudo systemctl status firewalld
# Add ports and https in firewall
sudo firewall-cmd --permanent --add-port=80/tcp && sudo firewall-cmd --permanent --add-port=443/tcp
# Allow services in firewall
sudo firewall-cmd --permanent --add-service=http && sudo firewall-cmd --permanent --add-service=https
# Allow the `443` port from `iptable`, `network`, `firewall` and `selinux`
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent && sudo firewall-cmd --zone=public --add-port=443/tcp --permanent && sudo firewall-cmd --reload && netstat -tulnpIf the application is running smoothly, then try make that up and runing with supervisor.
With supervisor, you can make any application running and controll the process of the application. It supports any kind of application like python, nodejs, spring-boot or any kind of application. We will run dotnet application. To do this, we need to create a .conf file in the previously configured folder (/etc/supervisord.d/) with this command-
sudo systemctl stop supervisord # stop supervisor server
sudo vim /etc/supervisord.d/xml_sign_asp.confIf the application is running smoothly, Then paste the following configuration and save with wq!-
[program:xml-sign-asp]
command=dotnet "StartupProject-Asp.NetCore-PostGRE.dll" --urls "http://*:80;https://*:443"
directory=/home/abrar/PublishedWebApp/
environment=ASPNETCORE__ENVIRONMENT=Development
user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=1
stderr_logfile=/var/log/xml_sign_asp.err.log
stdout_logfile=/var/log/xml_sign_asp.out.logsudo systemctl start supervisord.service && sudo systemctl enable supervisord.service && sudo supervisorctl reread && sudo supervisorctl update
sudo supervisorctl statusThis application generates a self signed SSL certificate for make the website https in the application and the application will run in 443 port, so we needed to allow port 443.
cd ~/asp && sudo rm -rf ./obj ./bin && git pull && sudo systemctl stop supervisord && rm -rf ~/PublishedWebApp && dotnet publish -c Release -o ~/PublishedWebApp && sudo systemctl start supervisord && cd ~ && tail -f /var/log/xml_sign_asp.out.logTo see application-log file, please run this command-
tail -f /var/log/xml_sign_asp.out.logTo see application-error-log file, please run this command-
tail -f /var/log/xml_sign_asp.err.logAnd to see the status of the app, please run this command-
#Check if supervisor is running
sudo systemctl status supervisord
# Check status of application in supervisor
sudo supervisorctl status
Supervisor with Ubuntu - https://www.atlantic.net/vps-hosting/how-to-install-and-configure-supervisor-on-ubuntu-20-04/