[No audio]
Web Server or httpd. This lesson is
very fun lesson. Because I promise you
at the end of this lesson, you're going
to be so proud of yourself that you're
going to create your own first website,
on your own server. So the purpose of
the HTTP service, or the web server is
what, is to serve the pages, right? Like
Google, Facebook, Hotmail, or whatever
the page that's out there on the
internet. And even let's say, if he
wants to sell something, or you want to
build your own website, or even your
profile website, and you want to build
it, you actually go and pay to companies
like GoDaddy or wix.com. But now you
could actually have your own machine,
and you can build your own website. And
you could publish it online so people
could see it, so you don't have to pay
it. But anyway, this is this, this
lesson, the purpose of this lesson is
not to tell you how to build your web
pages and publish it and without paying
anything. But this lesson is just
to tell you how web server works and how
we could build a web page in our Linux
machine. The service or package name
that needs to be installed or running in
our Linux environment is called httpd.
The files are the configuration file of
httpd is /etc/http/conf/httpd.conf.
This is the configuration file
where you make changes, allow
connections, run a specific
protocol, specify the user
directories, and a lot of bunch of
information. The next file we have is
/var/www/html/index.html. This
is your homepage. Whatever the changes
you make in index.html, this is what
is going to show up on your homepage. So
the service, to start a service or to
restart a service is systemctl restart
httpd. And to enable the service, which
means if you want the service to restart
or start, when your computer starts,
it's systemctl enable httpd. The log
files is /var/log/httpd/. So
this is the log file. If you are
troubleshooting any issues, you could go
into this log file and see why your
server is not working. Anyway, without
further ado, we will log into our Linux
machine and we will start our start
building our first page. And I will go
into my machine I got my IP address from
my machine and I logged in already, into
our PuTTY session. So I'm going to go into my PuTTY session,
[No audio]
become root.
[No audio]
You are logged in as root. Because I have
the pound sign here. Let's clear the
screen. Let's go back to our
configuration. The first configuration
file is, before we get into
configuration, we need to make sure we
do have the package for HTTPD, http package.
[No audio]
Yes, we do see right here this
is the package httpd centos, this one
httpd-tools, there are additional tools
that are available with this package.
And this is additional package that you
could install, whether that gets
installed automatically. Those are parts
of dependency. Anyway, the main package
we are concerned with this package, if
you don't see this package on your Linux
machine, you will simply have to run
yum, install http, and it will go in and
it will say I found a package for you, do
you want me to install it and you'll say
yes, and you installed. By the way since
I already have it it says, No package
http available. Or I would I should have
said d, and then it will say that package
this already installed and latest
version. Now once the package is there,
then let's go to our configuration file.
[No audio]
cd /etc/http/conf,
[Author typing]
httpd, sorry, this is
is httpd. Just make a correction, I have
skipped d, so cd conf,
and the configuration file is http.conf
So I will view this file and see if
there are any changes that I have to
make. For example, let's do more for
this file. And anything that you see
that starts with hash or pound, it means
it's just a comment. So you could ignore
that. And you could say, see right here,
it says the root filesystem for this
service is /etc/httpd, and it's going
to listen on port 80. What it means?
Every time you go to any website, all
websites, run on Port 80, or Port 443,
which is a secure website, which often
prompt you that this is a secure
website, do you want to continue, and
then you will say yes. So if you want to
change this port to some other ports,
then you have to specify on the browser
URL, and that's how you get in. But
anyway, this is a configuration file.
And another file that we have to find is
right here says DocumentRoot. This is
the one that I have listed here. It says
/var/www/html, and then the last
file. This is basically telling me that
the main page, or the homepage of your
web server will be located in this
directory. And there are many, many
other parameters that you could change
in this configuration file. The next,
the homepage file is the one that we
have to go to now, in order to start
making our page. So we'll go to cd /var/www/html,
and the file name is index.html.
Let's do ls -ltr, and
you will see here I do have a file name
called index.html. If you don't see this
file, don't get panic. Create this file
from scratch. And you know how to create
a file from scratch, you could do touch
command, or you could do vi command.
When I first created this index.html
file, of course, there was no file
existed in this directory. So I created
from scratch, I have already some of the
parameter sets, and my homepage set in
this file. So let's look at it. So I
want you to do vi index.html,
and then hit enter. The first thing is
in your page, you will always have to
type DOCTYPE HTML, and HTML code
always starts and begins with less than
and more than signs. This is how it
works. Now you notice, you are learning
HTML code. The next line, you will have
to specify that this is an HTML file. So
html, open, close. The next line I have
is body, what's inside or what shows on
my homepage. This is the body style,
background-color, lightgrey, this is
the lightgrey color I want from my
page. Then next one I have br. br stands
for break, I want a space. Then I have
h1 which stands for header one I have in my
header one, style text-align center, I
want it to show up right in the middle.
And Welcome to My First Page, and then
you close the header. Then you have
header four. These are the different fonts
actually, header one would have a bigger
font, header two lesser, header three
smaller, and smaller, and so on. And then
on the second line I have, My name is
Imran Afzal, and break, break, break,
close the body which you started right
here, if you notice inside of the body
right here. Now you closing it, and you
closing the HTML, right here when you
started. Every time you close these
tags, always put the slash. Now how do
we know what type of HTML code we have
to add more? That you have to go into
HTML class if you really want to learn
how to build your websites, but this is
just a basic lesson. I want you to
know if you want to get into IT or that
will definitely help you to get a job.
So I have all that and I want you to
type everything that you see here in
your index.html page, I have also
copied this entire content to the
description of this lesson. So you could
copy from there and type it from there.
Once you have it typed, then you could
simply save and quit.
[No audio]
Now, the fun part, how do we access that
page? To access this page, you have to
open up a browser, to view that page,
right? Okay, so how do we open the
browser? You need to know the address
like, you know, google.com or
hotmail.com? What is the address of
this? Well, we haven't put in this
address in a DNS. So then how do we
access it, we would access it from the IP
address. And the IP address is
192.168.1.12. So let's take this
IP address and put it in a browser. So I
have browser here, we'll put it this
right here. As you can see, right now,
make sure you are putting this IP
address on the same machine, where you are
running your Linux machine. So right now
is trying to connect and it is not
connecting, I think I know why. Because
every Linux machine by default runs
firewall. And you have to have a
firewall rules in place to allow port 80
traffic or simply disable it. I most of
the time, disable it. But again,
depending on your company regulations
and security policies, you should comply
with that. But for this training, I
would say go ahead and disable this
firewall. So I will do systemctl stop
firewalld. This is the name of the
firewall service, you hit enter. And it
has stopped the firewall. By the way, I
should have said that let's do the
start. It will start and before you stop
it, just check the status, whether it's
running or not. And if you had run this
command before stopping it, you would
have seen that it is up and running. So
that is why we are not able to get into
our homepage. So let's stop it now.
Okay, it has stopped. Let's go back to
your browser. And this time just hit refresh, or f5.
[No audio]
It is still not able to
connect. Let's see why? We have stopped
a firewall. Let's do ps -ef, grep
for firewall. It is not running right?
It's just grepping for grep then why is
not running? Think about it. I want you
to think about it, think like a system
administrator. Why is not running? Do
you know why? Let's go back to our
lesson. We have installed right here
look, service, we haven't started the
service itself. The service that's going
to serve the page, the service that's
going to take the request in, right, that
service has to run to actually have the
web server running. So let's go to our
the PuTTY session again, and now
start the service systemctl, but
before we start, of course, let's check
if it's running or not httpd.
inactive, huh, makes a lot of sense,
right? Yes, it's dead. That's why we
couldn't get to our Apache server. Okay.
Let's start it. It is started, now. Okay. Cross
your fingers. Go to web browser and do
f5 again. Ah, we got our first page.
Welcome to My First Page. My name is
Imran Afzal. Do you guys remember this is
the same message that I have in my HTML
text. Right? If you don't remember,
let's go back and do ls -ltr on
our directory, and you will see, do more
on index, and you'll see here, Welcome
to My First Page. And My name is
Imran Afzal. So this is the only two lines I
have. There you go right. So if you want
to modify it, let's say vi,
and I'll say,
[No audio]
take out this text and just put, I DID IT.
YAYAYAYAYA..No it's YAAY.
But yeah. Okay, anyway, so you got my
point. So let's save it. Okay, so now
what you should see here, right the
message that we change. So let's do a
f5, I DID IT...YAAY!. So that's how you
create your first page. Good luck.
[No audio]