1 00:00:00,000 --> 00:00:01,501 [No audio] 2 00:00:01,501 --> 00:00:06,510 Web Server or httpd. This lesson is 3 00:00:06,510 --> 00:00:10,230 very fun lesson. Because I promise you 4 00:00:10,230 --> 00:00:12,270 at the end of this lesson, you're going 5 00:00:12,270 --> 00:00:15,690 to be so proud of yourself that you're 6 00:00:15,690 --> 00:00:18,990 going to create your own first website, 7 00:00:19,380 --> 00:00:24,870 on your own server. So the purpose of 8 00:00:24,870 --> 00:00:27,990 the HTTP service, or the web server is 9 00:00:27,990 --> 00:00:32,310 what, is to serve the pages, right? Like 10 00:00:32,310 --> 00:00:36,180 Google, Facebook, Hotmail, or whatever 11 00:00:36,180 --> 00:00:37,860 the page that's out there on the 12 00:00:37,860 --> 00:00:40,410 internet. And even let's say, if he 13 00:00:40,410 --> 00:00:42,210 wants to sell something, or you want to 14 00:00:42,210 --> 00:00:43,950 build your own website, or even your 15 00:00:43,950 --> 00:00:47,550 profile website, and you want to build 16 00:00:47,550 --> 00:00:52,320 it, you actually go and pay to companies 17 00:00:52,320 --> 00:00:56,700 like GoDaddy or wix.com. But now you 18 00:00:56,700 --> 00:00:59,010 could actually have your own machine, 19 00:00:59,430 --> 00:01:02,160 and you can build your own website. And 20 00:01:02,160 --> 00:01:03,900 you could publish it online so people 21 00:01:03,900 --> 00:01:05,400 could see it, so you don't have to pay 22 00:01:05,400 --> 00:01:08,190 it. But anyway, this is this, this 23 00:01:08,190 --> 00:01:10,320 lesson, the purpose of this lesson is 24 00:01:10,320 --> 00:01:12,150 not to tell you how to build your web 25 00:01:12,150 --> 00:01:14,790 pages and publish it and without paying 26 00:01:14,820 --> 00:01:16,770 anything. But this lesson is just 27 00:01:16,770 --> 00:01:19,650 to tell you how web server works and how 28 00:01:19,680 --> 00:01:22,320 we could build a web page in our Linux 29 00:01:22,320 --> 00:01:25,620 machine. The service or package name 30 00:01:25,620 --> 00:01:28,650 that needs to be installed or running in 31 00:01:28,650 --> 00:01:32,400 our Linux environment is called httpd. 32 00:01:33,660 --> 00:01:36,930 The files are the configuration file of 33 00:01:36,930 --> 00:01:43,654 httpd is /etc/http/conf/httpd.conf. 34 00:01:43,654 --> 00:01:45,480 This is the configuration file 35 00:01:45,480 --> 00:01:47,400 where you make changes, allow 36 00:01:47,400 --> 00:01:50,190 connections, run a specific 37 00:01:50,190 --> 00:01:52,980 protocol, specify the user 38 00:01:52,980 --> 00:01:55,470 directories, and a lot of bunch of 39 00:01:55,470 --> 00:01:58,170 information. The next file we have is 40 00:01:58,170 --> 00:02:02,820 /var/www/html/index.html. This 41 00:02:02,820 --> 00:02:05,610 is your homepage. Whatever the changes 42 00:02:05,610 --> 00:02:09,330 you make in index.html, this is what 43 00:02:09,360 --> 00:02:13,740 is going to show up on your homepage. So 44 00:02:13,740 --> 00:02:16,500 the service, to start a service or to 45 00:02:16,500 --> 00:02:19,830 restart a service is systemctl restart 46 00:02:19,860 --> 00:02:24,720 httpd. And to enable the service, which 47 00:02:24,720 --> 00:02:27,510 means if you want the service to restart 48 00:02:27,540 --> 00:02:30,540 or start, when your computer starts, 49 00:02:30,840 --> 00:02:36,630 it's systemctl enable httpd. The log 50 00:02:36,630 --> 00:02:44,640 files is /var/log/httpd/. So 51 00:02:44,640 --> 00:02:46,680 this is the log file. If you are 52 00:02:46,680 --> 00:02:49,080 troubleshooting any issues, you could go 53 00:02:49,080 --> 00:02:51,510 into this log file and see why your 54 00:02:51,510 --> 00:02:55,410 server is not working. Anyway, without 55 00:02:55,410 --> 00:02:57,720 further ado, we will log into our Linux 56 00:02:57,720 --> 00:03:00,510 machine and we will start our start 57 00:03:00,510 --> 00:03:04,020 building our first page. And I will go 58 00:03:04,050 --> 00:03:09,000 into my machine I got my IP address from 59 00:03:09,000 --> 00:03:11,940 my machine and I logged in already, into 60 00:03:11,940 --> 00:03:15,034 our PuTTY session. So I'm going to go into my PuTTY session, 61 00:03:15,034 --> 00:03:18,004 [No audio] 62 00:03:18,004 --> 00:03:19,306 become root. 63 00:03:19,306 --> 00:03:22,492 [No audio] 64 00:03:22,492 --> 00:03:27,030 You are logged in as root. Because I have 65 00:03:27,390 --> 00:03:30,780 the pound sign here. Let's clear the 66 00:03:30,780 --> 00:03:34,350 screen. Let's go back to our 67 00:03:34,350 --> 00:03:37,800 configuration. The first configuration 68 00:03:37,800 --> 00:03:40,470 file is, before we get into 69 00:03:40,470 --> 00:03:43,410 configuration, we need to make sure we 70 00:03:43,410 --> 00:03:50,520 do have the package for HTTPD, http package. 71 00:03:50,520 --> 00:03:53,957 [No audio] 72 00:03:53,957 --> 00:03:56,250 Yes, we do see right here this 73 00:03:56,250 --> 00:04:01,050 is the package httpd centos, this one 74 00:04:01,440 --> 00:04:04,350 httpd-tools, there are additional tools 75 00:04:04,350 --> 00:04:06,390 that are available with this package. 76 00:04:06,630 --> 00:04:08,700 And this is additional package that you 77 00:04:08,700 --> 00:04:10,560 could install, whether that gets 78 00:04:10,560 --> 00:04:13,440 installed automatically. Those are parts 79 00:04:13,440 --> 00:04:16,560 of dependency. Anyway, the main package 80 00:04:16,560 --> 00:04:18,450 we are concerned with this package, if 81 00:04:18,450 --> 00:04:21,180 you don't see this package on your Linux 82 00:04:21,180 --> 00:04:23,160 machine, you will simply have to run 83 00:04:23,160 --> 00:04:28,470 yum, install http, and it will go in and 84 00:04:28,470 --> 00:04:30,420 it will say I found a package for you, do 85 00:04:30,420 --> 00:04:32,310 you want me to install it and you'll say 86 00:04:32,310 --> 00:04:34,440 yes, and you installed. By the way since 87 00:04:34,440 --> 00:04:36,690 I already have it it says, No package 88 00:04:36,810 --> 00:04:41,400 http available. Or I would I should have 89 00:04:41,400 --> 00:04:46,200 said d, and then it will say that package 90 00:04:46,200 --> 00:04:49,320 this already installed and latest 91 00:04:49,320 --> 00:04:51,570 version. Now once the package is there, 92 00:04:51,600 --> 00:04:55,560 then let's go to our configuration file. 93 00:04:55,560 --> 00:04:57,540 [No audio] 94 00:04:57,540 --> 00:05:01,394 cd /etc/http/conf, 95 00:05:01,394 --> 00:05:05,214 [Author typing] 96 00:05:05,214 --> 00:05:07,110 httpd, sorry, this is 97 00:05:07,110 --> 00:05:11,760 is httpd. Just make a correction, I have 98 00:05:11,760 --> 00:05:15,570 skipped d, so cd conf, 99 00:05:16,859 --> 00:05:20,336 and the configuration file is http.conf 100 00:05:20,336 --> 00:05:25,109 So I will view this file and see if 101 00:05:25,109 --> 00:05:26,729 there are any changes that I have to 102 00:05:26,729 --> 00:05:29,909 make. For example, let's do more for 103 00:05:29,909 --> 00:05:33,239 this file. And anything that you see 104 00:05:33,269 --> 00:05:36,479 that starts with hash or pound, it means 105 00:05:36,479 --> 00:05:39,119 it's just a comment. So you could ignore 106 00:05:39,119 --> 00:05:42,299 that. And you could say, see right here, 107 00:05:42,299 --> 00:05:44,789 it says the root filesystem for this 108 00:05:45,719 --> 00:05:48,869 service is /etc/httpd, and it's going 109 00:05:48,869 --> 00:05:51,809 to listen on port 80. What it means? 110 00:05:51,809 --> 00:05:54,599 Every time you go to any website, all 111 00:05:54,599 --> 00:05:59,339 websites, run on Port 80, or Port 443, 112 00:05:59,339 --> 00:06:02,129 which is a secure website, which often 113 00:06:02,189 --> 00:06:03,629 prompt you that this is a secure 114 00:06:03,629 --> 00:06:06,239 website, do you want to continue, and 115 00:06:06,239 --> 00:06:09,239 then you will say yes. So if you want to 116 00:06:09,239 --> 00:06:11,369 change this port to some other ports, 117 00:06:11,369 --> 00:06:13,679 then you have to specify on the browser 118 00:06:13,679 --> 00:06:15,779 URL, and that's how you get in. But 119 00:06:15,779 --> 00:06:18,089 anyway, this is a configuration file. 120 00:06:18,989 --> 00:06:23,579 And another file that we have to find is 121 00:06:23,579 --> 00:06:26,789 right here says DocumentRoot. This is 122 00:06:26,789 --> 00:06:30,749 the one that I have listed here. It says 123 00:06:30,749 --> 00:06:36,749 /var/www/html, and then the last 124 00:06:36,749 --> 00:06:40,199 file. This is basically telling me that 125 00:06:40,379 --> 00:06:44,789 the main page, or the homepage of your 126 00:06:44,789 --> 00:06:47,519 web server will be located in this 127 00:06:47,519 --> 00:06:49,619 directory. And there are many, many 128 00:06:49,649 --> 00:06:52,019 other parameters that you could change 129 00:06:52,049 --> 00:06:55,049 in this configuration file. The next, 130 00:06:56,219 --> 00:06:58,559 the homepage file is the one that we 131 00:06:58,559 --> 00:07:00,839 have to go to now, in order to start 132 00:07:00,839 --> 00:07:07,942 making our page. So we'll go to cd /var/www/html, 133 00:07:07,942 --> 00:07:11,837 and the file name is index.html. 134 00:07:11,837 --> 00:07:14,219 Let's do ls -ltr, and 135 00:07:14,219 --> 00:07:16,679 you will see here I do have a file name 136 00:07:16,679 --> 00:07:20,369 called index.html. If you don't see this 137 00:07:20,369 --> 00:07:23,819 file, don't get panic. Create this file 138 00:07:23,819 --> 00:07:25,919 from scratch. And you know how to create 139 00:07:25,919 --> 00:07:27,539 a file from scratch, you could do touch 140 00:07:27,539 --> 00:07:29,879 command, or you could do vi command. 141 00:07:30,419 --> 00:07:33,869 When I first created this index.html 142 00:07:33,869 --> 00:07:36,029 file, of course, there was no file 143 00:07:36,119 --> 00:07:38,159 existed in this directory. So I created 144 00:07:38,159 --> 00:07:41,339 from scratch, I have already some of the 145 00:07:42,179 --> 00:07:45,539 parameter sets, and my homepage set in 146 00:07:45,539 --> 00:07:48,059 this file. So let's look at it. So I 147 00:07:48,059 --> 00:07:51,029 want you to do vi index.html, 148 00:07:52,710 --> 00:07:57,750 and then hit enter. The first thing is 149 00:07:57,870 --> 00:07:59,610 in your page, you will always have to 150 00:07:59,610 --> 00:08:06,090 type DOCTYPE HTML, and HTML code 151 00:08:06,270 --> 00:08:09,660 always starts and begins with less than 152 00:08:09,690 --> 00:08:12,930 and more than signs. This is how it 153 00:08:12,930 --> 00:08:15,240 works. Now you notice, you are learning 154 00:08:15,270 --> 00:08:19,050 HTML code. The next line, you will have 155 00:08:19,050 --> 00:08:22,620 to specify that this is an HTML file. So 156 00:08:22,620 --> 00:08:27,510 html, open, close. The next line I have 157 00:08:27,540 --> 00:08:31,470 is body, what's inside or what shows on 158 00:08:31,470 --> 00:08:34,710 my homepage. This is the body style, 159 00:08:34,860 --> 00:08:38,039 background-color, lightgrey, this is 160 00:08:38,039 --> 00:08:39,960 the lightgrey color I want from my 161 00:08:39,960 --> 00:08:44,159 page. Then next one I have br. br stands 162 00:08:44,159 --> 00:08:47,909 for break, I want a space. Then I have 163 00:08:47,940 --> 00:08:52,110 h1 which stands for header one I have in my 164 00:08:52,110 --> 00:08:55,110 header one, style text-align center, I 165 00:08:55,110 --> 00:08:57,120 want it to show up right in the middle. 166 00:08:58,020 --> 00:09:01,410 And Welcome to My First Page, and then 167 00:09:01,410 --> 00:09:03,510 you close the header. Then you have 168 00:09:03,510 --> 00:09:06,000 header four. These are the different fonts 169 00:09:06,000 --> 00:09:07,590 actually, header one would have a bigger 170 00:09:07,590 --> 00:09:10,290 font, header two lesser, header three 171 00:09:10,290 --> 00:09:13,770 smaller, and smaller, and so on. And then 172 00:09:13,770 --> 00:09:15,690 on the second line I have, My name is 173 00:09:15,720 --> 00:09:19,020 Imran Afzal, and break, break, break, 174 00:09:19,110 --> 00:09:20,940 close the body which you started right 175 00:09:20,940 --> 00:09:23,010 here, if you notice inside of the body 176 00:09:23,010 --> 00:09:25,410 right here. Now you closing it, and you 177 00:09:25,410 --> 00:09:27,510 closing the HTML, right here when you 178 00:09:27,510 --> 00:09:30,450 started. Every time you close these 179 00:09:30,450 --> 00:09:35,700 tags, always put the slash. Now how do 180 00:09:35,700 --> 00:09:38,790 we know what type of HTML code we have 181 00:09:38,790 --> 00:09:43,350 to add more? That you have to go into 182 00:09:43,350 --> 00:09:45,630 HTML class if you really want to learn 183 00:09:45,630 --> 00:09:47,760 how to build your websites, but this is 184 00:09:47,760 --> 00:09:50,100 just a basic lesson. I want you to 185 00:09:50,100 --> 00:09:53,880 know if you want to get into IT or that 186 00:09:53,880 --> 00:09:56,760 will definitely help you to get a job. 187 00:09:57,720 --> 00:10:01,050 So I have all that and I want you to 188 00:10:01,050 --> 00:10:03,540 type everything that you see here in 189 00:10:03,540 --> 00:10:07,200 your index.html page, I have also 190 00:10:07,200 --> 00:10:09,870 copied this entire content to the 191 00:10:09,870 --> 00:10:11,820 description of this lesson. So you could 192 00:10:11,820 --> 00:10:13,440 copy from there and type it from there. 193 00:10:13,620 --> 00:10:16,560 Once you have it typed, then you could 194 00:10:16,560 --> 00:10:18,690 simply save and quit. 195 00:10:18,690 --> 00:10:34,590 [No audio] 196 00:10:34,590 --> 00:10:38,010 Now, the fun part, how do we access that 197 00:10:38,010 --> 00:10:40,950 page? To access this page, you have to 198 00:10:40,950 --> 00:10:43,410 open up a browser, to view that page, 199 00:10:43,410 --> 00:10:46,110 right? Okay, so how do we open the 200 00:10:46,110 --> 00:10:48,150 browser? You need to know the address 201 00:10:48,240 --> 00:10:49,620 like, you know, google.com or 202 00:10:49,620 --> 00:10:51,420 hotmail.com? What is the address of 203 00:10:51,420 --> 00:10:53,430 this? Well, we haven't put in this 204 00:10:53,430 --> 00:10:56,430 address in a DNS. So then how do we 205 00:10:56,430 --> 00:10:58,410 access it, we would access it from the IP 206 00:10:58,410 --> 00:11:01,350 address. And the IP address is 207 00:11:02,970 --> 00:11:06,810 192.168.1.12. So let's take this 208 00:11:06,810 --> 00:11:10,290 IP address and put it in a browser. So I 209 00:11:10,290 --> 00:11:12,330 have browser here, we'll put it this 210 00:11:12,330 --> 00:11:16,020 right here. As you can see, right now, 211 00:11:16,110 --> 00:11:18,330 make sure you are putting this IP 212 00:11:18,330 --> 00:11:20,160 address on the same machine, where you are 213 00:11:20,160 --> 00:11:23,040 running your Linux machine. So right now 214 00:11:23,040 --> 00:11:25,050 is trying to connect and it is not 215 00:11:25,050 --> 00:11:28,560 connecting, I think I know why. Because 216 00:11:28,890 --> 00:11:31,470 every Linux machine by default runs 217 00:11:32,070 --> 00:11:34,860 firewall. And you have to have a 218 00:11:34,860 --> 00:11:37,950 firewall rules in place to allow port 80 219 00:11:37,950 --> 00:11:41,550 traffic or simply disable it. I most of 220 00:11:41,550 --> 00:11:43,230 the time, disable it. But again, 221 00:11:43,230 --> 00:11:45,480 depending on your company regulations 222 00:11:45,480 --> 00:11:47,910 and security policies, you should comply 223 00:11:47,910 --> 00:11:50,400 with that. But for this training, I 224 00:11:50,400 --> 00:11:52,290 would say go ahead and disable this 225 00:11:52,290 --> 00:11:57,360 firewall. So I will do systemctl stop 226 00:11:57,630 --> 00:12:00,630 firewalld. This is the name of the 227 00:12:00,630 --> 00:12:03,690 firewall service, you hit enter. And it 228 00:12:03,690 --> 00:12:07,140 has stopped the firewall. By the way, I 229 00:12:07,140 --> 00:12:09,270 should have said that let's do the 230 00:12:09,270 --> 00:12:13,410 start. It will start and before you stop 231 00:12:13,410 --> 00:12:14,820 it, just check the status, whether it's 232 00:12:14,820 --> 00:12:18,990 running or not. And if you had run this 233 00:12:18,990 --> 00:12:21,030 command before stopping it, you would 234 00:12:21,030 --> 00:12:23,940 have seen that it is up and running. So 235 00:12:23,940 --> 00:12:26,310 that is why we are not able to get into 236 00:12:26,310 --> 00:12:28,950 our homepage. So let's stop it now. 237 00:12:30,390 --> 00:12:32,430 Okay, it has stopped. Let's go back to 238 00:12:32,430 --> 00:12:36,250 your browser. And this time just hit refresh, or f5. 239 00:12:36,250 --> 00:12:39,988 [No audio] 240 00:12:39,988 --> 00:12:41,520 It is still not able to 241 00:12:41,520 --> 00:12:44,520 connect. Let's see why? We have stopped 242 00:12:44,520 --> 00:12:47,760 a firewall. Let's do ps -ef, grep 243 00:12:47,760 --> 00:12:52,530 for firewall. It is not running right? 244 00:12:52,560 --> 00:12:54,870 It's just grepping for grep then why is 245 00:12:54,870 --> 00:12:57,930 not running? Think about it. I want you 246 00:12:57,930 --> 00:12:59,400 to think about it, think like a system 247 00:12:59,400 --> 00:13:02,580 administrator. Why is not running? Do 248 00:13:02,580 --> 00:13:06,000 you know why? Let's go back to our 249 00:13:06,000 --> 00:13:09,480 lesson. We have installed right here 250 00:13:09,480 --> 00:13:12,570 look, service, we haven't started the 251 00:13:12,570 --> 00:13:15,180 service itself. The service that's going 252 00:13:15,180 --> 00:13:17,430 to serve the page, the service that's 253 00:13:17,430 --> 00:13:19,890 going to take the request in, right, that 254 00:13:19,890 --> 00:13:22,740 service has to run to actually have the 255 00:13:22,740 --> 00:13:25,260 web server running. So let's go to our 256 00:13:26,300 --> 00:13:28,500 the PuTTY session again, and now 257 00:13:28,500 --> 00:13:31,920 start the service systemctl, but 258 00:13:31,920 --> 00:13:33,690 before we start, of course, let's check 259 00:13:33,690 --> 00:13:36,242 if it's running or not httpd. 260 00:13:37,636 --> 00:13:40,680 inactive, huh, makes a lot of sense, 261 00:13:40,680 --> 00:13:42,720 right? Yes, it's dead. That's why we 262 00:13:42,720 --> 00:13:45,150 couldn't get to our Apache server. Okay. 263 00:13:45,960 --> 00:13:52,530 Let's start it. It is started, now. Okay. Cross 264 00:13:52,530 --> 00:13:56,130 your fingers. Go to web browser and do 265 00:13:56,160 --> 00:14:01,530 f5 again. Ah, we got our first page. 266 00:14:01,560 --> 00:14:04,200 Welcome to My First Page. My name is 267 00:14:04,230 --> 00:14:06,570 Imran Afzal. Do you guys remember this is 268 00:14:06,570 --> 00:14:11,040 the same message that I have in my HTML 269 00:14:11,040 --> 00:14:13,650 text. Right? If you don't remember, 270 00:14:13,650 --> 00:14:15,870 let's go back and do ls -ltr on 271 00:14:15,870 --> 00:14:18,300 our directory, and you will see, do more 272 00:14:18,300 --> 00:14:21,000 on index, and you'll see here, Welcome 273 00:14:21,000 --> 00:14:23,790 to My First Page. And My name is 274 00:14:23,790 --> 00:14:26,100 Imran Afzal. So this is the only two lines I 275 00:14:26,100 --> 00:14:28,890 have. There you go right. So if you want 276 00:14:28,890 --> 00:14:31,906 to modify it, let's say vi, 277 00:14:33,031 --> 00:14:35,567 and I'll say, 278 00:14:35,567 --> 00:14:37,650 [No audio] 279 00:14:37,650 --> 00:14:45,161 take out this text and just put, I DID IT. 280 00:14:45,161 --> 00:14:49,560 YAYAYAYAYA..No it's YAAY. 281 00:14:49,980 --> 00:14:53,670 But yeah. Okay, anyway, so you got my 282 00:14:53,670 --> 00:14:57,180 point. So let's save it. Okay, so now 283 00:14:57,180 --> 00:14:58,950 what you should see here, right the 284 00:14:58,950 --> 00:15:00,900 message that we change. So let's do a 285 00:15:00,900 --> 00:15:07,530 f5, I DID IT...YAAY!. So that's how you 286 00:15:07,560 --> 00:15:09,780 create your first page. Good luck. 287 00:15:09,780 --> 00:15:10,614 [No audio]