Instructor: Web server or httpd.
This lesson is very fun lesson
because I promise you at the end of this lesson,
you're gonna be so proud of yourself
that you're gonna 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 webpages, right?
Like Google, Facebook, Hotmail,
or whatever the page that's out there on the internet.
And even, let's say if you wanted to sell something
or you wanted to build your own website
or even your profile website
and you wanted 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 could build your own website
and you could publish it online
so people could see it so you don't have to pay.
But anyway, this is...
This lesson, the purpose of this lesson
is not to tell you how to build your webpages and publish it
without paying anything,
but it's, this lesson is just to tell you
how web server works
and how we could build a webpage 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 or the configuration file of httpd
is /etc/http/conf/httpd.conf.
This is the configuration file where you make changes,
allow connections, run on a Pacific 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's gonna 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/http.
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'll log into our Linux machine
and we will 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 gonna go into my PuTTY session.
Let's become root. (keyboard clacking)
We are logged in as root 'cause 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.
Yes, we do.
See right here? This is the package, httpd centos.
This one, httpd-tools,
there are additional tools that are available
for this package.
And this is additional package
that you could install with it
that gets installed automatically.
Those are part of the 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 install it.
By the way, since I already have it,
it says, "No package http available."
Or I should have said D,
and then it would say that package, this,
already installed and latest version.
So once the package is there,
then let's go to our configuration file,
cd/etc/http/conf. (keyboard clacking)
HTTPD, sorry.
This 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 file system
for this service is /etc/httpd,
and it's gonna listen on port 80.
What it means, every time you go to any website,
all the websites run on port 80 or port 443,
which is a secure website
which often prompts you that this is a secure website,
do you want to continue?
And then you will say yes.
So if you wanted 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,
it 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.
Then 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 always have to type DOCTYPE space 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 would 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 light gray color I want for 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.
You started the body right here.
Now you're closing it and you're closing the html
right here when you started it.
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 that 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.
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?
We would access it through 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,
I will putted this right here.
As you could see right now,
make sure you are putting this IP address
on the same machine where you're running your Linux machine.
So right now it's 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.
It is still not able to connect.
Let's see why.
We have stopped the firewall.
Let's do ps -ef, grep for firewall.
It is not running, right?
It's just grepping for grep.
Then why it's not running?
Hmm. Think about it.
I want you to think about it.
Think like a system administrator, why it's not running?
You know why?
Let's go back to our lesson.
We haven't start.
Right here, look, it's a service.
We haven't started the service itself,
the service that's gonna serve the page,
the service that's gonna 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. Hmm, 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 your web browser and do F5 again.
(instructor laughing)
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 Iran Afzal.
This is the only two lines I have.
There you go, right?
So if you wanted to modify it, let's say vi,
and I'll say take out this text and just put
"I DID IT. YAAY!"
No, that's yayayaya not yay. (laughs)
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 changed.
So let's do F5.
I did it. Yaay. (laughs)
So that's how you create your first page.