Apache Server | Setup Virtual Host on Ubuntu Server 20.04

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys is Josh from keep attacking and today I want to do a quick video showing you guys how to set up a patchy virtual hosts engi by two 2904 [Music] okay so a patchy webserver is like one of the most popular methods of serving websites to the Internet and Apache is part of the lamp stack which is Linux Apache MySQL PHP that's typically the stack that people set up when they're creating a web server well Apache is the program that actually serves the websites and today I want to show you guys how to actually set up virtual hosts now if you don't know what virtual hosts means it's a way to serve multiple websites from one physical server and Apache can't handle this by setting up virtual hosts so just to give you an example let's say you gotta keep your techie calm and linux.com you can serve both of those websites from one server using virtual house so that's what I want to show you guys how to set up today and it's a very simple process so let's get started okay so I have a fresh Ubuntu 2204 server running in virtual and I'm connected to a via SSH and I want to go and walk you guys through how to actually do it first thing you need to do is actually install Apache on the system if you don't have it there so I'm gonna run that command right fast so you guys can just see that process so let's press enter first thing you need to do is update the system though so you update your system it'll refresh the repositories and also check to see if you have any updates on the system as you can see this this system is it's fresh it doesn't have any updates I updated it when I installed it a little bit earlier so the next thing we need to do is install Apache and the command to do that is sudo out install apache2 and that's the actual package name just just so you know it's not a patchi's apache2 so let's press ENTER on that and this will go through and do the installation of Apache and also you might want to include this with MySQL as well as PHP if you plan on developing a front and back in type website but if you're only creating something in HTML or the new markdown language then you don't need to install like you could just have the web server up and running and that way you serve the websites and it's almost finished okay cool so Apache is installed on the system and we can check it by running sudo systemctl status Apache and press enter and I apologize Apache - and press Enter as you can see it's actively running so our server is up and running and also another way of testing is actually going to the IP address there is a patchy default page that's created on the server under voor www HTML folder on the server so let's press Q to just bring it back to the terminal actually let's clear I we all need to see that and the first step is actually creating the directory structure and what I mean by directory structure is the location where the website files will be stored and just to show you the location for that and actually let's just create a folder so you can see the location but the location is sudo let's see sudo and I'm gonna actually make the directories so make directory I'm gonna do - P there that way it'll create any of the folders that I don't have there but for www and I have two of my personal domains that I may use for this and the first one is actually music daiki pataki calm and you can name these folders whatever you want - I'm a name I'll just mute music but most people will name it the actual domain so if this was like I'm using a sub domain so music that keep its techie dot-com most people set up a day website folders like this which is is good product that way you don't know specifically the folder of the website that you have running because if you have like 20 different websites it's best to put it in that format that way you can you know separate everything you know nice and neat instead of just a name like what I'm putting but this is just fine for me so I'm gonna just put this in there music and as well I have another domain it is car kid pro got us saw my ad that one here as well so please just run the same command and I'm a name that folder kid pro that'll be the directory that we want to set up set it up for and the next thing you want to do is actually change the permissions on that folder and I won't go into all of these permissions I think I did a video on setting permissions but it's not work to understand once you get it but the command to change the permission chmod - or capital or make sure it's capital or and then seven five five and this will basically give it read access so people on a general web can actually access directory this directory and then we're gonna I'm gonna do it at the top level that way it catches both of those folders so if we go for www and that's why I used the - or because that's recursive it'll go through it'll go down in a directory tree so to catch all the folders underneath it so that music folder and a kit pro folder will get those permissions as well so if we press ENTER here that will give those folders those permissions and we get to check those permissions very fast just by typing L LS - LA and this will show us those permissions and as you can see it has read and execute on both of those folders and this is the default folder right here which is generated when you actually install Apache so that's already already there and it should have a file in there basically letting you know that Apache has been installed properly on the system okay and just to save some time I went on and generated some HTML code for each one of these sites so at the end of this demonstration when I'm showing you that it actually works you can actually see something on the screen when you open up the web site so I'm going to go in and create a HTML file under each one of these directories so let's go sudo nano for www and let's create an index dot HTML file in there and press ENTER and let me go it on and paste this in there right first boom so this is the HTML code that we test out once we finish setting up the virtual house so let's do the exact same thing for the music directory and press ENTER and then I have just some code on that one as well just tailored to these domains so make sure they work boom so now we got our our HTML files located in the directories that we need now let's go down and set up the virtual host and before I do that let me check some life as I want to see what the permissions are on each one of those HTML files so let's go to kit Pro and look at it okay so that's not gonna be read by it so let me bring through and and run the chmod again that we had a modifier those those index dot HTML files that I put in there and let's just check the kit Perl when it doesn't matter I know the other one I work if this one you know it's set because we did it at the top level or a higher level in the tree so we get to go and so let me clear this right fast now let's get in and create the virtual host okay so in Apache or ported the configuration files is that create a default config for the sites available and this is the file that you actually need in order to create the virtual host so if we go and actually let's CD to these this directory that way you guys can see what's in it so let's go CD etc' Apache and it's Apache - and then and in sites available boom and then let me LS this directory so you guys can see what's in here and what we want to see or what we want to look at actually is the 0 0 - default dr. fate this is the fire we want to use not sure why my system is freezing up like that but so let's actually make a copy of this and so we need to use pseudo because it's under a directory on bar by root so let's go CD I mean pseudo copy and then we could type zero zero darker fee and what you want to name it is and I like to do this just to make sure those in the right in a proper place I put period in a four slash this basically lets the system know that you want to copy it within the directory that you're in this is just a simple way of me doing it but dart for slash and then I want to name it something I want to name it something specific to the website and this is where I like to name it the full domain name so I'm gonna do the music one first so music die keep it techie dot-com diet Kumpf so doc config so make sure you name it in that format and then press Enter I'm not gonna make the config for the other one because I want to go in and modify this one first so let's go sudo nano music dark hippo I mean that keep attack attack on that config so we want to go in here and this is actually the virtual house file so just so you know don't get confused with all these comments they put all these comments in here just to help you how to set it up or whatever and December I mean I always leave that body I'll leave that default but this is where we want to start to type in so the first thing you want to type in is the server name and you need to type it in the right format so just capitalize the s capitalize the end and then just put a space there between it and you want to type the server name or the actual domain name and this one is the music that keep its techy calm and the next thing you want to do is put the server alias and and really all this is doing is including @ww and actually that's just make it quick by copying what we got here and pasting down right here and go to the front of it type www.hp.com/support music that I keep it's a key calm and that's pretty much all you have to do now for my instance in order to get my domains to work I have Cox Communications is for my service provider and they block port 80 so I can't host web sites on port 80 I have to use like a non-standard port which I always use like 8080 in order to get to my websites from the outside if I need to so you have to change if you're gonna use a non-standard port you have to change that to that port number as well as open up that port in your firewire if you have you to firewater turn on which hopefully you do and I'll show you how to open up that firewall after we finish these configuration files so that's pretty much it for this first config so we're gonna hit controls control X and type Y to save it and let's go down and copy that config file we just created the music 1 and we want to create our new one which is kit pro that us start config and press enter and let's go to modify this one and the reason I want to modify this one because it has everything in there it has the server name and a server alias in there so all we have to do is change it out for the right domain name so who type sudo nano and then kipper that us that config and if we go down here it has the right port and all we gotta do is change this up so Skull Kid Pro us and it's going on highlight this and let's go it on it highlight this copy and it's going on in and drop this in here after the www and then now let's go down and change our directory which this one was kid pro and that's pretty much it so we can hit ctrl C I mean ctrl X and then Y to save it and we're good to go okay so now that we created those configuration files and got them set up for our two domains now we need to enable them because they're actually not enabled at this point you have to physically enable them you can create up as many create as many virtual houses you want under sites available but the only way that it'll start working is if you enable them and the way to do that is it's a quick command and it's pseudo and it's a tool and that stands for Apache 2 and en si te so that's Apache 2 enables site and you want to specify the configuration so let's start with the first one which is music I keep it a key that kaamdar config press enter on that one and as you can see it's enabled on that one and the only and the only way for the side to start working as well you have to reload Apache in order for it to basically pick up those new configuration files that we enabled so let's do the same thing for kit pro right fast so let's enable that site as well so kit pro boom and just to show you what happens it basically copies the new configuration over to an enabled folder so as you can see when the sites available so that's where you actually create the configuration files so if we go up one directory and I'm just showing you this so you guys wouldn't know we'll know but if we LS this directory to Apache 2 directory I'm gonna do LS - LA so you see there's a config available there's a configure table there's a Mars available there's Mars enabled and there's a sites available and incise enabled none of this stuff of work once none of these configuration files are working they're moved to the enabled directory and you can't just simply move it there you have to run that command that and I'm not sure what the command is for the mines and the config I can't remember I've taught my hair right now but I know 88 to enable a to Ian site will enable the configuration for each domain configuration or site configuration so we get to go there and one thing they recommend you do when you set up virtual host or multiple domains when you're patching server is to disable the default configuration in the command to do that is sudo a - and it's di site which basically disables site and I apologize this D is so disabled site basically this is what it stands for and then you want to go in inside that cafee which is the domain config or the default configuration and we could D we can disable that site now that all that's done we can go down and restart apache so the way you do that is simply sudo system CTL restarts apache to impress inner that'll restart it and let's go down and check the status very fast as you see it still it still is active and running it's been restarting so we good to go so let's quit that or actually press ENTER it's fine not all that's doing you want to go down and open up the ports on your server as well as create port forwarding on your router now I'm not gonna show you that because everybody has different routers so I can't just show you my router and how to actually you know do it on my router it may not apply to you know anybody that watches the video which I you know I have a small cry so it doesn't make any sense to actually show me setting up port forwarding on my router because it may or may not apply to you so I'm just gonna show you how to open up the ports on the server which which is pretty simple to do so let's see D that way we can get out of CTC directory and let's clear write fast but the command to open up the ports is simply sudo ufw and actually let's look at the status first just see and it's not active so let's go it on in enable its and press Enter and it may or may not kill my ssh connection but whatever it looks as though it did no it didn't I think I got port I think I have port 22 I already opened so you have W status again oh and port 2022 is not on air so let's go sudo ufw allow SSH and then let's look at the status again I just want to make sure and then also let me go ahead on and allow a port 8080 right fast press enter and this will get the status one more time in Port 80 80 is open now so we should be good to go now I already have the domains pointing to my heart business my outside up users so the site should come up in an don't worry about China you know I guess hack cuz imma shut down this server as well as changed my domains back to my main hosting server which is out you know it with a hosting company so you guys don't get my IP address but okay so that's pretty much it let's go down and try to test the size right fast so I'll be back in a second okay cool so I have my brothers are up let's go down to test these websites so the first one was music that keep attacking our comm and as you can see I already kind of tested it but port 8080 you have to use port 8080 of you if you have to use a non-standard port but if it's if you have a service provider though that does a block port 80 then you just type in that you know the domain name as usual but since I I can't do it I have to use the 8080 but anyway so if we press ENTER on it that's that HTML file that we actually created on the server so success the music that Cuba techie diakon virtual host is working and also just to show you that the other one is working as well as get per hour us start on port 8080 so that virtual host is open and that should give you a clear understanding of how virtual hosts work you got multiple domains on one server being served out so I hope you guys enjoyed the video please like share and subscribe to the channel I'm gonna keep coming with the Linux content because my whole goal is to try to get more people and to use our open source software as well as the Linux operating system so so if you have any questions leave comments down in the comment box below and of course keep it techie [Music] [Music]
Info
Channel: KeepItTechie
Views: 16,946
Rating: 4.9379311 out of 5
Keywords: LearnLinux, Linux, Tutorial, Review, Howto, Guide, Distribution, Distro, Learn Linux, operating system, os, open-source, open source, gnu\/linux, ubuntu, ubuntu 20.04, 20.04, ubuntu lts, LAMP, linux, apache, web server, php, linux tutorial, tutorial, KeepItTechie, learn linux
Id: rvwYzs6IMog
Channel Id: undefined
Length: 22min 21sec (1341 seconds)
Published: Sat May 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.