Hey everyone and welcome back to another skill in the LPIC 2 certification course.
Okay so what we're going to be focusing on in this skill right here is all about being
able to set up a web server.
Now there are different types of web servers available that you can use on Linux.
The main focus for us right now is going to be an Apache web server.
Now all Apache is, it is an open source utility.
Now if you don't know what open source is, it just means that the source code for the
project is widely available.
You can actually read this source code and it's not just open to read, it's also free
to use under the Apache license.
So naturally this makes a very good web server to use because it's not going to cost you
anything, you can easily see the code to see how it actually operates.
This really is a great solution for us, especially for demo purposes and because we do want to
be knowing this once again for the LPIC 2 certification.
So really what is an Apache web server used for?
We'll think about it.
What it's going to do is going to allow us to serve up web pages so no real big revelation
right there.
Now what this actually means is that we can serve up these services to our internal users,
perhaps you want to present some type of web page to them to be able to manage their own
system or if we so choose we can present this web page as a front facing external website
that could be reached over the internet.
The reality is how the Apache web server is implemented is completely flexible and up
to you.
Now the way Apache works is by leveraging something called HTML.
Now if you happen to have much familiarity with web development you will actually understand
or be at least familiar with the concept of HTML.
But if you're not familiar all HTML is, it stands for the Hypertext Markup Language.
And all this is going to be doing is going to provide us a type of structure that we
can use so that we can display the pages that we want on to our website.
It is the language that our web browsers can read.
So if on your website you want to have maybe some bullet points like point one, point two,
so on and so forth.
Or if you want to embed some type of images maybe say some JPEG images or you want to
format your actual text into paragraphs whatever it may be.
Perhaps you want to add in different headings.
Maybe you want to use headings of different sizes for more important issues and smaller
headings for less important issues.
The reality is all of this can be done using HTML which like I say is what Apache is going
to leverage.
Now with respect to Apache actually using HTML so that we can ultimately render our
web pages all of this hinges upon particular configuration files.
And like so much of what we learn within the LPIC certification courses, the actual location
of these configuration files are of primary importance.
So we do actually want to be knowing whereabouts these configuration files that Apache is going
to leverage.
We need to know where exactly they are and unsurprisingly there actually is once again
a difference depending on if you are using a Red Hat based system or a Debian based system.
Now with respect to Debian based systems the actual package itself is simply known
as Apache 2 and this package on Debian is going to be located within the Etsy directory
and then within a folder simply titled Apache 2.
So really easy to remember the name of the package is basically within the Etsy directory
itself.
Now things are a little bit different with respect to Red Hat based systems like I say
the actual package itself is not going to be called Apache 2, the package is going to
be called HTTPD.
Now the reason for this is because in order to access web pages we are going to be actually
accessing that data using the HTTP protocol.
This is the Hypertext Transfer Protocol.
This is what you see when you use your web browser.
So this might be a little bit confusing.
This is the transport we use to get the information and the information we are consuming is leveraging
HTML.
That is the difference but basically here this is just the Hypertext Transfer Protocol
deamin effectively.
Now on a Red Hat based system this HTTPD package is going to be once again located within the
Etsy directory but this time in a folder called HTTPD.
So that really is the difference.
The package name is going to be in the Etsy directory just like we saw with the Debian
based Apache server package.
So these packages are going to reside within these respective folders and within these
particular folders we are going to have like I say these configuration files.
Now these configuration files are not just going to be one large monolithic file that
contains absolutely everything like so much of what we see within Linux.
These are actually going to be modular such that effectively the configuration files are
broken up into small chunks.
This once again like we see before makes things a lot more manageable so as opposed to dealing
with a huge configuration file that controls absolutely everything.
We will be dealing with more specific and smaller files that control very particular
aspects of the configuration.
Like I say a common theme on Linux because this architecture happens to work really
quite well.
Now with respect to our Debian based systems there is quite a unique directory structure
that we have to talk about.
The first thing that I really should mention is that the main configuration file is going
to be one called Apache2.conf.
Now within this configuration file we are actually going to point to additional folders
and these folders are going to be one called sites-enabled and the other one is going to
be mods-enabled.
Now these actual folders are what are called simlinks.
Now we actually talked about simlinks in the Lpik1 certification course so no doubt you
are familiar with this concept.
So all these folders do in effect then is point to additional folders.
So let me show you what the relationships actually look like.
Let's take for example this simlink first.
So sites-enabled.
This simlink folder is actually going to point to a folder called sites-available.
That is the relationship right there and with respect to our mods-enabled the mods-enabled
simlink folder this one is going to point to a directory known as mods-available.
And within these actual folders that we see here we are going to have a whole bunch of
configuration files that have to be loaded by the system in order to operate correctly.
But you might be asking why even bother having these simlinks right here.
Instead why doesn't the Apache 2.con file just not point to this directory directly.
Well the reality is by invoking our simlinks it just simply makes things more manageable.
So let me tell you why this is because think about it if we have our simlink sites enabled
which really just points to this main directory of sites-available.
If we want to temporarily disable any of the configurations that are within this directory
right here we don't actually have to go in and delete anything here because if we happen
to go into this directory and delete those files then we could lose them forever.
Instead if we just want to disable that behavior all we could do is simply and temporarily
remove this simlink and by doing this we actually haven't changed anything physically within
this directory but we've broken the link to this directory so it's not actually going
to be active.
And once again if we want the configurations within this directory to once again become
active once more well we just recreate this simlink once again to point to this file or
this directory should I say and then all the configurations within this folder structure
are going to be active once again the same is true of the mods enabled simlink which
points to the mods available directory structure.
So really this is all about making things much much easier as well as by the way much
safer to manage because like I say you're not having to go in and physically remove
configuration files from the actual disk itself.
Now like I say we do have differences between Red Hat and Debian with respect to Red Hat
we no longer have this Apache 2.conf file no surprises since the actual package is not
called Apache 2.
Instead you can probably guess what the configuration file is going to be called instead the main
configuration file here is going to be HTTP.conf so a little bit different once again.
Also with respect to Red Hat we're not actually invoking this simlink behavior instead this
configuration file HTTP.conf this just points to a directory structure known as the conf.d
directory and within this directory structure we have the configuration files that the web
server needs to actually operate and we just interact with them directly as opposed to
the way we do it on the Debian based system.
Okay so now that we have a rough idea of how Apache actually operates within these systems
how about we actually take a quick peek at what these configuration files do now in order
to do so the first thing I'm going to have to do is to install the Apache web server
package now I happen to be on a Debian based system so I'm going to install the Apache
2 package not the HTTP package so what I will do here is I will say sudo apt update and
I'll type in my password okay Apache 2 and I will do dash y to answer yes to the prompt
and the installation will begin okay so now that I have actually installed this I should
now have this directory right here so if I go into etsy and go into Apache 2 this now
exists now what we're going to see here is what exactly I talked about remember these
particular files say for example or rather these particular directories should I say
the sites available the sites enabled the mods available and the mods enabled now the enabled
ones are going to be our sim links so if I do an LS dash L on mods enabled and list everything
in here we can see here that indeed we actually have all these sim links that point to particular
configurations and these actually live within the mods available directory see that there
but in mods enabled but the point to mods available and once again we can tell these are sim
links with these little arrows the highlighting and more concretely we have the little L at the
very left hand side right here and similarly if I just clear the screen and I do an LS dash L on
sites enabled once again we're going to see sim links and here in this case we only have a
singular sim link but as you'll notice it points through the sites available directory so we could
go into these directories such as the sites available and if I do an LS right here we can see
these are the actual configuration files that are ultimately controlling the behavior here but we
can like I say access them within the sim link so I can go into the sites enabled directory do an
LS we can see we have this configuration file right here if I do a sudo nano on this configuration
file we can see a whole bunch of information so right here we can actually see that this
particular service is going to be running on star which means on any IP address i.e. any IP
addresses we have configured on our server this service is going to listen on any of those IP
addresses on port 80 now port 80 is a well-known port for web access so this should come as no
surprise but we also have some additional information here which is really quite important this one
right here is indeed very important the document routes this is really going to be the main
directory that is going to hold all of your files with respect to your service so within here the
var directory www and then the html but actually going to find html files that are going to be
ultimately rendered by the Apache service for our web pages now the other file I want to show you is
that main configuration file we talked about remember on Debian based system this is going to
be called Apache 2.conf so if I go back a directory right here so I'm in the Apache 2 directory I do
an LS here is this main configuration file right here so if I open this one up as we can see here
this is the main server configuration file for the Apache server itself if we scroll on down we
can actually see such things as the include optional keyword which is actually specified we're
going to load the configuration files within the sites enable directory and we can see here we
actually have a wildcard value which is the star meaning that any file within this directory that
ends with .conf is going to be read as a configuration file so if we go back we're going to sites
enabled we do an LS-L any configuration files that we can see here the end in .conf which is this
sim link here this is going to be read in and again it just points to the sites available
directory where we have the physical location for this configuration file and like I say that Apache
2.conf configuration file has way way way more information than we can actually cover within
this nugget now what we actually saw within this configuration file like I say we can see this
document root so how about we go and have a look at this particular directory then so we'll go back
out and I'll go into my var directory go into www and then HTML if I clear the screen to a PWD and
LS we can see this index dot HTML configuration file right here now if I happen to open this we're
going to see a whole bunch of HTML and you don't have to worry about all of this particular
formatting here this is HTML code you do not have to be able to be a web developer who is very strong
on this just understand what you happen to be looking at here this is just effectively instructions
for how our web page is going to be rendered so what we actually have here is this index dot
HTML file like I say and this is actually going to be a default file that the Apache web server
is going to look for and read so if everything that is in this configuration file is going to be
read by Apache and ultimately rendered that means what we actually see in this file we could
actually view it via a web browser now one thing I will do right now is I will check my IP address
I'll say IP adder we can see my local address is 192 1680 44 if I browse to this address in a web
browser we should actually see the contents of this index dot HTML page right here so let's try that
then so I'll go to my virtual machine browser right here I'll type in the IP address 192 1680
44 if I hit enter the browser is actually showing the Apache to default page this is ultimately
what we see within the contents of that index dot HTML file so what I can do here is if I go in and
I just maybe say remove this okay so it no longer exists in fact I need to do a pseudo RM so now it
no longer exists what I'll do is I'll recreate it okay so I'll say HTML now what I'm going to do here
is some very basic HTML now you don't have to be worrying about being able to write this HTML
code I just want to show you a basic example here so I'm going to use these particular
tags h1 and then a closing tag of h1 this h1 is just simply to create a heading so I can just say
this is a big heading welcome to the page and then I can create a smaller heading using an h2
label or an h2 tag so you've found IPv0s web server and I'll do a closing tag for h2 and I can make
an even smaller heading using an h3 heading hope you have a great time and I'll create another h2
heading which will be of medium size so a little bit bigger once again come back again soon okay so
if I happen to save this file right here we now have this index dot HTML recreated if I go to my
web page and I reload this check this out we can see here the main heading for the web page we have
a medium size heading then a small heading then again another medium size heading now of course
this is a very very basic web service there is nothing too savvy with the html code that we're
seeing here but ultimately the point remains the same we have these particular configuration files
that are ultimately going to be referencing particular pieces of html which we can feed
into the Apache web server that can ultimately render this service which we can then expose to
our internal users as a private web page or if we so choose expose it as a public web page to be
consumed by regular users on the internet so that is us for our introduction into Apache I hope this
has been informative for you and I'd like to thank you for viewing