Hi, my name is Beyhan and i am here with you with our fourth video in the first three videos we have seen how to install ubuntu on virtual wax and how to configure sftp and exercise to reach and to manage our ubuntu server after that we have seen how to install postgresql server on ubuntu virtualbox and how to manipulate data with pg admin and in our third video we have seen how to use entity.net framework to connect postgresql with a c sharp application in third video we have created a c-sharp console application to write and read data from postgresql and we also create the web application to read and to write on postgresql in this video we will see something interesting you'll be deploying over applications.net core applications to linux as same as you will be doing on windows so that netcast cross platform and you'll see how we can benefit from that so in this video we'll be touching a few domains one of them will be windows and net developments another one will be deploying our.net application to ubuntu and network applications are using internal web server called kestrel web server ksi web servers are planned to be used as secondary web server that means first you will be using an iis and is will be forwarding requests to castral so actually it is configured by default to run on 127.0.0.1 in this generic ip address same thing applies on linux site it is planned to be first request will be coming to apache then this request will be directed to cassave web server and you'll learn in this video all of them how to do configurations ip configurations port configurations and how to forward requests from apache to cash drag how to do firewall settings and how to manage virtualbox port forwarding now let's continue with our visual studio we will open the application that we have developed in third video i am using visual studio 2022 and visual studio 2022 supports.net 6 which is the latest version of that net core and if you are using 3.1 there are just minor changes in the code visual studio 20 22 uses that need six so we need that net six sdk if you have installed visual studio you will automatically have the sdk and same thing required in linux site minitab.net 6 on linux site as well and we will see how to install net6 sdk on linux and how to run our application the same as we will be doing on windows as i mentioned before our web application is using dot net 6 if i double click on the project we will see the framework details which we are using and as you can see here it is that net six and we need to install on ubuntu .net 6 before we continue build if chains on our controllers we will add a simple method to read all the data from postgresql database or postgresql databases located on ubuntu server so i will start my virtual machine and we will be able to manipulate data on postgresql so previously what we have done is we have created the logs controller for all logs table and we will be edited in action we can add a string to our log table and now we have our third method another action and to call that we will be doing just log slash read all what it will do is it will go to our db context it will connect the oscilloscope database it will go to logs table it will read all the entries and it will create a error list with it and we did area this will be reading only the log 1 field and we will concatenate all the log 1 fields in its string and we will return the string if we get an exception we will catch it and we will return exception message and in line settings of our project i will also change default launch url to this so if i write here logs slash read all that should be sufficient same thing here and if i run the application web application it will open a browser window and we will be able to call our actions if you haven't been following me from the third video what you can do is you can simply create a web application a network web application so what happened is now because web servers start you can see it is listed in localhost 5024 port and other default or default controller action so it should be reading logs tables and it should be returning us to log columns data and it's working fine let's use another one by using add action and i will call that and it has been done if i read again [ __ ] action now you should see our new string here that's fine now we know how to run it with visual studio and let's try it how we can run it from console actually we thought that we can simply call.net command and the web application dll and it will trigger the ksr web server then service will be running it to background you will see it then we can actually make the same calls so what i will do is i will go to visual studio i will stop our solution and i will right click and publish our application i have done publish before so if you are publishing first time you will see this window and you will choose folder and you click next you can choose your publish folder location but i will leave as default one so you can click finish and it will create this publishing profile for you and then you will just need to click publish button here or as an option you can simply run the publish commands which is here.net publish configuration with this okay publish is complete then in output window we can see the publish folder location if you don't have output window just go to view and click output from here and it will open output for you so what i will do is i will go to powershell which i have here but i won't be using this one just to show you actually it is nothing to do with visual studio this time i will simply run a powershell or cmd i will call the dotnet command and all the ad and ksr the publications will start working i write cmd i will go to folder that i have copied to paste just right click on the console i go to d drive and now if i say dot net info i see all the details about dot net format i have here so i can run it that means i have dot net now if i say dot net is again web application iot.dll it will start running again the kestrel server you can see the port is 5000 this time and if i go to web browser if i say local hosts five thousand i need to write the whole path logs and reads all as you can see web server is running we haven't created a series of anything simply by calling.net command and dln it has triggered web application and started ksl web server it started to listing all the records from localhost 5000 and we got the response but what happens if i change the ip address this localhost only works on this machine not even network in order to reach this ksi web server i need to enable cancer to listen the local ip address where i need to set up iis reverse proxy and i don't want to use is in this case so what i will do is i will just show you if i try the same request with my local ipad is this time i will open powershell which is much better than cmd and i will close this window you'll continue with powershell if i write ipconfig to see my local ip address and which is here 192.168.561. instead of low cost i will be writing it here 192 .168.56.1 so this is refused to connect it doesn't allow us to connect to this site and other thing is actually we are not running our web application first we need to write okay casserole is running at the background but it doesn't listen 192 1 68 56 one so it won't be showing any response to us no so what we will do is i will close this window i will go to programs of web application this is again.net six so code is a bit different than core if you are using code you need to go to program class again and you need to do these bits you need to adjust this line under startup discord i know my ip address so i will just copy this ip address this is windows ipad this is we have seen on powershell if i go to powershell again just remind you just make the things clear to understand i go to ipconfig and this is the ip address right so i need to enable castrate to run on this ipad address too and also on localhost i change this one to localhost local is same as 127.001 so if you write localhost that means you actually have access to this ip address tool i saved it i will rebuild it then i will publish it again rebuild succeed now we will continue publish and i will click publish again i will copy the pets one more time and again i will write dotnet and i will write pet web application right it will be web application dll this time you'll see two ip addresses as you can see this time case is listening both this address and this address so if i go to browser if i press enter here this time castrate is listening this address sorry port numbers let's check for now 50 24 that's it now it's working fine again if i write it 127 0 0 1 it's working fine again if i write here localhost which is same as 1.7001 and it's working fine so this is how you can actually run cast server without using is and it is exactly the same in linux i will show you in a second and just to show you how you can run a console application i will publish console application will say publish and it has been done too so i copy the page one more time i will just simply end this by pressing ctrl c again i will write darknet to run console application and paste it console ubuntu dot dll you can see hello world and it will be reading data from postgresql server and it has been done as simple as that as same as java is same as python you can now run.net core applications in any platform just by using dotnet commands now let's learn how to run dotnet applications on ubuntu first we need to check if we have dotnet on ubuntu to do that we can simply write.net on terminal window and if it shows information then we have it otherwise it will show command not found and it says command not found so we will install.net sdk then we will have dotnet command i open a browser page we will search for net sdk ubuntu installation we will click for microsoft page and if we scroll down are distributions so we need to know what's the ubuntu distribution for that we will be using usb release commands it is twenty zero four so i will click twenty zero four and i will be copying the first command here i will go to terminal right click paste and that has been done i will continue with the second one copy terminal paste enter and it has been completed too we will continue with the third one right click paste and enter that has been done too so we will continue following directives i will copy this whole bits right click paste and enter and here we got some issues with our repository it cannot connect to that so let's fix it and then we will continue with the second command we need to change over repository urls so to do that we need to edit the source file under etc apt sources list and here i will change all the trs to fr so instead of turkey repository site will be connected to french repository site ctrl s ctrl x and now i need to run second command again i paste it again and press enter okay that installation is completed and we have installed.net sdk which contains dotnet runtime and by using dotnet sdk we can actually develop dotnet applications by using dotnet command line interface cli so let's see if we have dotnet now as you can see we have the dot net and if i write dot net info and we can see the details and where the dot net is located so it is under usershare.net and there's a.net replication here so this part is done now we just need to copy over that net application from windows to ubuntu and then we will be running just.net command as we have done in the windows powershell or in the command line so to copy we will be using sftp and before we continue we actually need to change ip addresses of that web application remember if you want to connect some uh as then 1.7001 you need to give the ip address but this ipad this is windows ip address and we need to provide here the ubuntu ip address and we need to remove this ip address because it will try to open port connection for the given ip address and it won't be able to find this ip address on ubuntu and it will give us an error so first we need to check our ubuntu ip address to do that we go to terminal and if we write if config we have 10 0 to 215 ip address here so we just need to provide and i will be writing here so we have changed the ip address and we will be just publishing it again before publish i will do build solution and build is completed now we will just right click again you will select publish here we will publish the same folder i will copy to pads and i will open this folder in file explorer paste the bit here press enter and i will copy this folder to ubuntu with filezilla so i have already created the site on filezilda and we reach filezilla and we reach ubuntu with port forwarding on virtualbox you can see the details on the first video i will say connect we see the data folder of sftp and i will just drag and drop publish folder here transfer is completed now we can run our.net application since that will be a web server application i will create a proper folder for it i will create a folder under var wwe and i will give a name web api and i will be copying publish folder contents to this folder so to do that i will say copy all from sftp my folder data publish all the contents to www web api and if you go to this folder and you'll see we have all the files here and we need to change permission of these files they need to be executable that has been done with chmod command now we can list the contents again if you want to see the permissions use ls all and we can simply run.net commands as we have done on windows and i will say web application dot the l as you can see castrate is already running and it is listening both ubuntu ip address and also it is also listing local ipads generic ip address so if i go here if i open a new tab if i write 127 0 0 1 50 50 24 logs read all so as you can see we have all the data from postgresql and if you want to add new ones as we have done on windows we will just say logs controller name and action name and the parameter for the action and that will be test string digital and okay and if you check it again from from logs read all and we got all the data and we can check if it is destiny it is ubuntu ip address as well as you can see it's also working fine and it is as simple as that you just need to do exactly the same thing as we have done on windows and you just need to run.net command with a web application dll it will be triggering again the web application it will start running kestrel web server and it will start listing the ip other samples you have provided and this is how we can run castle web application server on ubuntu without using apache if you provide permissions to firewall you will see we can actually reach it from windows machine as well let me show you how we can reach cancer web application server from windows i press ctrl c and i stop running kestrel web server so what i will do is i will just save to the ufw hello and i will give the port number on tcp protocol rule is edited now i will just enable it that's it now if i go to my virtualbox i will do port forwarding for port 5024 i go to settings network advanced we'll support a new move here i will say dotnet guest rally 5024 and i will forward it from my generic local ip address 5024 again i can do any port number but just to keep it simple i will use same port and that's it now if we start again or dotnet commands web application.net commands now castrate is listening again if i go to google browser google chrome browser on windows if i write 127001 5024 logs and read all it should be working just fine as you can see it is working that's because we allowed kessler web server to run on local ip address and we have done port forwarding from virtualbox to from our windows host ubuntu ip address if we didn't write this line here it wouldn't be it wouldn't allow us to connect from non-local ip addresses so this line is important here to be able to connect outside from our machine our next step will be creating the started web application as a service so it will be running at the background so simply by running dotnet command here you can run.net core application on linux and if you allow firewall and if you do port forwarding on virtualbox you can simply reach over ksi web server from outside ip addresses such as i have done with my windows host machine so now i will stop web application server by pressing ctrl c now we will create a service which will be running at the background so we will be able to reach our.net web application without running.net commands as we have done previously here i will create a service file then i will be running four commands it and it will be done so i have these notes on my windows i will connect to ubuntu with putty i will connect to ubuntu password ubuntu and i will just create a new service file i got putty right click paste and the password again now we need to copy these lines to our new file so what we have here is the description or for our service and the second line where our web application is working and and here we have dotnet's location and it is installed under usershare.net.net this is the command we are running and this is the whole path for our application dln i press ctrl s ctrl x now we will copy these commands and this command will enable our web api service it's fine and we will start it as we start in other service done and now we will check the status of our service it is active and running as you can see we have we got same output here now i can close it and check it on ubuntu as well so if i say sudo services web api status it is doing exactly the same thing that we have done with dotnet command and output is exact same so that means our web application is running at the background even if i close the terminal window i have closed the terminal window it is running ssrs at the background now it should be able to get all the data and it got so just check it just to be sure i will run again logs at action tests.net service it's it okay and i will be reading all the data again you can do the same thing on windows i open the chrome browser log3doll this is the exact same object we can use our ksr web server as standalone web server without apache and now i will show you how actually we can use apache web server as perks web server forward request to kestrel to do that i will open another participation here first we need to make sure apache will be listing our ports that we'll be using i will be using port 88 so i first i need to go to apache ports config file and we need to add this following commands we need to go to etc empire g2 and here we have port com file if we do sudo nano of course conf password is ubuntu and i will be adding this line here listen 88 ctrl s ctrl x and then we need to installing two modules to forward our request to be able to use apaches proxy server paste it press enter that has been done and then second commands paste it and enter that has been now too and what we need to do is we need to add spot forwarding virtual host directives on configuration file we need to create a new com file for our web ip and automatically a page will be checking all the chrome files under conf enables folder so i go to putty again press enter now i just need to copy and paste it here but remember we are not using 50 5000 port we are using 50 24 ports and again 52.4 so what it will be doing it will be forwarding any requests coming from 88 to 50 24 regardless of ip address and now we just need to restart a patch of course to be able to reach 88 port we need a load on firewall and we need to enable yes now we can check if we can reach from 88 and we can try it on ubuntu if i say 88 it's working just fine but this time it is actually passing to request from apache to kestrel via 88 port and i will go to virtualbox settings i will add apache 88 port forwarding rule here i got networks advanced power forwarding and i will say apache 1.7001 and 2 10 0 2 15 88 okay now if i go to again my browser on windows instead of 50 24 if i write 88 it's working just fine again so it's working just fine at the background you can see there is ubuntu and here or chrome browser on windows source it's just working fine so basically by adding virtual hosts on apache configuration and by enabling port on ports com file you can forward all the requests that's coming outside from ip addresses to local kestrel so in that case actually you don't need anymore to add this ip addresses to kestrel that we have done visual studio it can run on default settings it can just simply run local url remember what we have done here in the program cs we have edit these lines for ubuntu now we don't need to add them because as default it will be listing just this ip address and since we will be reaching our kessler web server from local ip address because of reverse proxy that we have done on the apache settings we don't need anymore other ip addresses i hope you understood what we have done by using these urls and what is reverse proxy now in the next step i will show you how to enable ssl and https on ports by using apache web server we will be connecting via https to do that first we need to run a few commands one of those apt-get update i go to putty and now we will be installing open ssl on apache copy the commands paste you can find all this document content on youtube as description to the video so you can copy these commands from there and change according to your needs it has been done too and with the third command fourth one we need to add new lines to apache conf so we opened it with nano editor we are going to end off the file and here we can add this directive ctrl s ctrl x and we need to create a folder to store our certificates and private keys for ssl we will be doing that with the maker commands that has been done we are going to this folder and now we will be running open ssl to create the private keys this is country name just two characters province and now the organization name nothing organization unit nothing this common name parameter is important here we need to be entering our ip address so it will be 10 0 2 15. even address we can just give a random email address here and we have created all certificates if we show the content we have this private key and public key now we will continue to enable ssr you just need to add this three line statements so if you go to all conf file for web api which was under enabled sites so conf enabled we have our web api conf file here i will open it with nano and before the end i will be just pasting these three lines that's it now we can reach our site with ssf but before we do that obviously we need to restart apache and password is ubuntu done now if you go to ubuntu we should be able to connect via 88 from https i will just change url to https okay accept all the risks because certificates have signed it's not globally designed so now we have our secure connection and if we try to reach it from windows host we can use https2 it is exactly the same thing it will be slash 127 0 1 88 30 88 controller name and the action with all it's again giving the same warning to us because this is not a trusted certificate i just want to continue to site where is it yeah here proceeds that's it so in this video we have learned many things from different domains i hope you enjoyed this video if you do so please click like button and don't forget to subscribe hope to see you in the next videos thanks for watching