Basics of Apache Webserver

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome to my channel in this video I'm going to talk about the basics of Apache web server I did a video on the basics of Apache web server a long time ago probably my first video and it sounds like the video has been useful to a lot of people and so I decided to redo this video and try to make it a little better for some of you this may be a very basic topic please stay tuned for my more advanced videos this tutorial is based on CentOS 7 but the basics will be the same for other operating systems except some of the commands that we are going to use to install and manage the application apache HTTP server is commonly known as apache that is free and open source cross-platform web server and is one of the oldest and most reliable web server around the internet it's maintained by Apache foundation let's talk about what a web server actually is a web server is a server software that can serve HTTP requests when a client browser requests a file over HTTP protocol the web server accepts the request finds the requested document and sends back to the browser if it cannot find a requested document a 404 is sent back to the browser a web server also processes web application files written in various programming languages such as PHP into a static HTML file the HTTP protocol itself is textual and is stateless application protocol what that means is the server or the client are not aware of their previous requests and is not tracked by either the client or the server now let's get into actual installation and configuration of the Apache web server we're going to utilize the RPM command to check if the Apache web server is already installed in the system rpm stands for Red Hat package manager and maintains a database of all the installed packages in the system we can issue rpm command with a cue flag to query the database and find out if the package is already installed if the package is not already installed in order to install the Apache web server we will use the yum command yum stands for a yellow dog updater modified and is a free and open source command line package management utility for Linux operating systems that use the RPM package manager I'm locked into a CentOS 7 machine and will use this to demonstrate how to install and configure the Apache web server let's query the RPM database and find out if the Apache web server is already installed the package name for the Apache web server is httpd so we're acquiring the RPM database to see if the httpd package is already installed on this computer so the RPM package manager tells us that the package is TTP D is not installed you could also do our p.m. minus QA which means query all the packages and grep for the HTTP to find out if the httpd package is installed now that we see that the httpd package is not already installed let's go ahead and use the yum command to install the Apache web server yum installed is DT PD with the httpd package it is also going to install a dependency the HTTP D - tools which has the other utilities like HT passwd which used to generate the basic authentication password let's go ahead and say yes and that's basically the installation of the actual httpd package now the web app a a web server is actually installed in this machine let's go ahead and repeat our RPM - queue command now I would say is that the HTTP D is installed and we see the version number of the package you can also do the RPM - QA and then do a grep for the ctp so we'll get the same result so we see that the httpd and httpd - tools are installed on this machine there are a couple other packages that may be of interest so if you wanted to have the purl support you could install mode underscore Perl so you can install any Apache modules with the yum install mode underscore and in the package name install that so now we have the support for a pearl in our Apache web server similarly if you wanted to have the PHP support you would install PHP and most of the times if you have PHP you are most likely going to be talking to the database so you would install PHP that's my sequel as well so now our webserver also supports the PHP if you wanted to install the OpenSSL or the SSL support then you would install open ssl and the mode underscore ssl packages we're not going to be talking about the SSL configuration in this video but that can be a topic for a separate video that's actually add for the installation of the Apache web server and some of the commonly used packages now that we have completed the installation of the Apache web server we need to know how to manage this service in this slide I've listed some of the most common and useful commands that you can use to actually manage the service the first command the systemctl command can be used to check these status of the Apache web server you can check whether or not the application is running you can also use the system CTL command to start the service stop the service reload the configuration file when you make any changes to the configuration file or actually start the server next we can use the netstat command to check if the Apache web server actually is listening on the poor's we wanted it to so by default the Apache web server listens on port 80 and 443 if SSL is enabled and installed however you could force it to listen on other non default ports so you can use the netstat command to check and make sure that the apache web server is listening on the appropriate port the other command is the PS command that you can use to see if the Apache web server is actually running there's another command the HTTP D command which you can use with the - T flag to check the syntax of the configuration file when you make changes to the Apache web servers configuration file before restarting or reloading the configuration it is a good idea to check the syntax and make sure whatever change was made to the configuration file is correct so you can use the HTTP D - T command to make sure that the syntax is correct and then httpd with the - V flag can be used to check the version of the Apache web server running on your system let's see this in action let's start with the system CTL status command self systemctl status is T TBD it tells us that the Apache web server is in active then so that means that the application is not running so we could go ahead and start the Apache web server with the system CTL start HTTP D now that you know the services started we can check these status and this time we can actually see that these service is active and running let's go ahead and use the system CTL stop command to actually stop the service let's go ahead and check the status one more time and we can see that the service is stopped let's go ahead and issue the restart command and this time now and now the application is running now that the application is in running a state let's go ahead and check the status of the port's that it may be listening in to with the netstat - to pan command grab - i HTTP and this tells us that the apache web server is listening on port 443 and port 80 and we can see the process ID of the apache web server you can also do the same thing with netstat - to pan and then grab for 80 or 443 that gives us the same result however if we were listening on an on default port then we could just grab with that port number and be able to tell whether or not the Apache web server server is listening on the custom port similarly we can just do the PS aux and then correct for HTTP so we can see that the multiple threads are running for the Apache web server we can also quickly demo the HTTP D minus T command and it says that the syntax is okay I can see that mrs. D could not reliably do to mine the server's fully qualified domain name that's because the server name directive is not set on the Apache web web server configuration we'll we'll take care of that later and finally the HTTP D minus V command that gives us the version and the built information for the Apache web server package that is installed on this server now that we know how to install in man is the Apache web service let's talk about some of the key files related to the Apache web server on a default centerís installation the main configuration file for the Apache web server is located at / Etsy / httpd / conf / httpd.conf and that HTTP default file also includes anything that's in the can't daddy folder and ends with a dot conf in the file name the log files for the installation are located at slash var slash log slash HTTP D there's going to be a default access log and a default error log the PID file for the default install is located at slash VARs last run slash HTTP D slash HTTP DP ID and then the startup script for the system D is located at slash USR slash lib system D system httpd dot service and then if you are on an older version of the Centaurs operating system and or using the init script then the startup script is located at slash etsy init.d httpd let's take a look at some of these figuration files we can see that there are a couple files there in the Etsy httpd.conf folder so if we look at the httpd.conf httpd.conf this is the main configuration file for the Apache web server the configuration file itself is well commented and you can actually read through this configuration file to understand a lot of the options and configuration that can be made to the Apache web server and then you can also see that at the end we have a line that says include optional count D slash start con which is what causes the Apache web server to include all the files that end with dot-com and reside in the contactee directory let's take a look at the PD count dot d directory and we can see that there is the Pearl dot-com that's the result of us installing the mod Perl the PHP conf is a result of installing the PHP package the ssl.com because we installed the mode SSL and there's the welcome and the user dare calm all these files that end with the dot-com are gonna be loaded into the Apache main configuration now let's take a look at the log files so if we go to our log SDPD we can see that there are a couple log files there you can override this on a per host basis but these are the default log files the access log which has the access log the error log has all the errors logged into that file and then similarly you have the access log and the error log for the SSL as well as the request log for the SSL next is the PID file that's located as HTTP T dot PID if you cat that file you will see the process ID for the Apache web server we can confirm that by typing TTP and you can see that the nine five nine one the parent process ID is stored in the PID file similarly if you look at the Israel live system D system HTTP d dot dot service this is the start of a script for the Apache web server on the center seven if we want it to ensure that the Apache gets started every single time the server is booted up we need to enable enable the httpd service and it creates a symlink so that it starts on every boot let's go back to the Apache main configuration file and talk about some of the most important options in the Apache web server main configuration file there's the server root directive that specifies the root directory for the web server configuration the listen directive that specifies what interface and port to listen on the include directive is used to include files into the configuration as we saw earlier where it included all the dot-com files from the contactee directory the user in the group keyword are used to specify the user and the group for Apache to run as by default it is set to Apache and Apache the server token keyword is used to specify what server token to expose for any error phases and stuff like that the default is set to operating system which means it's gonna expose the operating system information as well as the Apache web server information and the version information when someone hits a 404 or 500 error piece so it's highly recommended to change the product only so that it shows that the underlying web server is Apache but does not necessarily expose the operating system or the web server version information next keyboard is the server signature keyword that is recommended that be set to OFF what that does is that disables exposing the webmaster or the server administrators email into the error pages and so forth let's go ahead and actually look at all of those directives that we talked about so opening up the actual configuration file let's go towards the top so you can see that the server root keyword is present on the config file so the server root keyword actually defines the root of the Apache web server and further down in the configuration we're gonna see that the reference is made to the directories and files are relative to this root directory of the web server next we see the listen directive and you can see that a well commented line out there if you have multiple IP addresses or multiple interfaces on the web server you can specify to only listen on particular IP addresses and particular port or with the current configuration where it says less than 80 it is basically listening on all available interfaces on port 80 the next keyboard the input queue were like we talked multiple times it just includes all the files into the main configuration file the user and group Apache Apache as default they specify the user and group under his privileges the Apache web server is going to be running next we can see the server admin and it says root at localhost so we talk about the server signature keyword that defines whether or not to expose this information or the virtual host server admin email address when an error page or 404 or a 500 error page is hit by the client the directory option I did not mention that earlier and I'm probably gonna cover in follow-up video it is used to set for a directory basis permissions and override configurations to a particular directory the document root keyword is this one is a default document root so basically if someone hits the web server on a port 80 then it is served it serves the document from this web document root when we do the virtual hosting then we create a virtual host block and define the document root relative to that particular website it's going further down there's the AF module keyword that is actually used to set the include the modules the additional modules for the Apache so this one in particular is including the directory module it checks to see if the directory module is present and then defines the directory index as the index dot HTML what that does is a user hits the web server and a particular port without specifying a file name that's gonna load the index dot HTML as the default file the files keyword here it is basically just saying that do not serve any file that starts with dot HT its configuration in in an attempt to secure the AC access and is T past LD files that are that may have sensitive information like user information and password information that will probably cover in the follow up videos the error log this error log here defines the global error log configuration the log level specifies the logging level you can do one debug notice critical so by default it is set to one there's the log config module so Apache lets you configure the log format to your liking so we see that this is the common log format there's the combine log format the combine i/o log format and then if you want and you can define your own custom log format and then you can use that in your virtual host log configuration it's going further down further down this enable send file option is an option in the newer version of Apache web servers and this controls whether the apache web server may use the same file support from the kernel to transmit the file contents to declined by default when the handling of a request does not require access to data within the file for example when you know it does not need to process when serving this static file the Apache uses the send file to deliver the file contents without actually reading the file if the operating system supports that option so you can use the enable send file option and set it to on and can speed up the delivery or the serving of the static files that do not need to be processed by the Apache web server so these are basically all the important keywords and directives that are available in the Apache web configuration file you can also see whatever options have been enabled on the Apache web server bike adding the file and then doing a grep - V and exclude anything that starts and ends so basically like a blank line or anything that starts with space and then ends so you can see these are all the options that are enabled on this web server I hope that covers the most of the basic configuration for the Apache web server it's now time to actually understand the different types of hosting options available there are basically two types of hosting that can be configured on the web servers so one is the name based hosting or the name-based virtual host and in the IP based virtual home basically what that means is you can either identify a website being hosted on the same web server by IP or by the name of the host in the name-based virtual hosting multiple websites are hosted on the same IP address and then the name virtual host and an IP address keyword is added into the Apache configuration file and in this directive is no longer necessary in the newer versions of the Apache you can try adding that and then if it says if it errors out or if it says that this is this does not have an effect and it's going to be deprecated in the newer releases then that means it does not need that option and you can just comment that out in the IP based virtual hosting each website has its own dedicated IP addresses and then you don't necessarily identify the website to be served with the name of the web server and basically if you reach that interface that IP address on that particular port it's gonna serve you the web content for the virtual host in order to do the IP based virtual hosting you're going to require a dedicated IP for each website that you are going to host so you might have to configure the single network interface card with multiple IP addresses now that we have a firm understanding of the basics of Apache web server let's go ahead and configure a demo virtual host and then browse it to make sure that the configuration actually works in order to configure the virtual host we can either just write the configuration into the Apache main web configuration file in the CTBT conf and we can just go to the bottom end and start configuring our virtual host or we can actually create a separate file and then create the configuration in the content directory with the file ending with the dot conf extension or you can actually include a whole new directory whole new extension type into the configuration file for this demo I'm going to create demo conf and configure a virtual host starts with the virtual host keyword and then you can either specify the IP address that you want to listen on if you're going to be doing the IP based hosting or you can just let it on all interfaces on port 80 now you define the server name which is what identifies what documents to serve based on the name based hosting we're going to say example.com the server alias you can use this aurelius to specify additional names that should take you to this website for example example.com or anything that example.com next you might want to define the server admin example or the webmaster at example.com the document root is the next configuration which is what defines the root of the document for this particular website so when a client browser requests a certain while the web server is going to look for that file in this directory so let's say for doubles of dot HTML and an example dot-com next you can either define the error log and the custom log if you wanted to or it could just take the it would just take the global configuration and log to the same place if you wanted to define the log file errorlog you would say logs example.com that's underscore log or whatever so this lets you organize the error log and the access log for separate websites in a separate file the next is the custom log that's going to be logs example.com that's access underscore log and then for the custom logs you can actually specify the format we discussed earlier in the main configuration file so for this example we are going to use the common log format and the next is the directory index by default I believe it's going to be index dot HTML because we saw that in the default Apache configuration file so you can say index dot HTML or you can even say main dot HTML or main dot PHP or whatever the default file that you want to serve when the clients come to your web server without specifying what file they want to be served now we just need to close the virtual host tag and that's basically it for the configuration now we need to do the syntax checking all right so it says invalid command error log of course because I typed it wrong so that's going to be a lot now you can see the advantage of running the syntax check before actually restarting the server if you were to restart this server and it would actually stop but it wouldn't be able to start so now we see that the syntax is OK and it says localhost see if I can fix that as well the ICSD conferred calm server name we can just see and we put the example.com then it's gonna try and look for well it's gonna look for the DNS resolution of the name so we want to put the name that can be resolved so basically the local domain we have a real web server that resolves to an IP address you can put the name there or you can just set the IP address as a comment above it says that let's try and see that again so alright that error is gone now what it is complaining about is the document root example.com doesn't exist so let's go ahead and create that directory ok as there will make it owned by Apache and group ownership achi EML example.com and then let's see what was our directory indexed main dot HTML so we'll go ahead and create VAR dub dub HTML example.com main dot HTML that's gonna be the file that is going to be serve to the clients when they do not specify a file name let's say it's the main HTML file for example.com this is going to be our demo content now in order to actually browse this site by name example.com and because the example.com does not resolve to our IP address what we are gonna do is in our HC host file we're going to add 1 to 7 0 1 as the IP address of the example.com and we should be able to reach that now at example.com so when we browse the example.com it's just going to point us to the to the server now that we have checked these syntax and everything looks good let's go ahead and reload the configuration file system CTL reload httpd and now we can actually go ahead and do HTTP dub dub dot example.com and then we skip the actual main HTML file for example.com now if we wanted to we can actually install a text-based browser yum install links and say links HTTP let me just clear the screen now links example.com okay and then you can see the main HTML file for the example.com domain you can actually browse it from your computer but you would have to update the Etsy host file with the IP address of the web server that's all for the basics of Apache web configuration I hope to create future videos for you know more advanced topics on the patchy web server configuration that may include like configuring the Apache web server for PHP support you know other advanced configuration like SD access and all that good stuff but I hope this video was useful to get you started with the Apache web server let me know if you liked it in the comments and then please like share and subscribe if this video was helpful and I hope to see you all in the next video thank you for watching [Music]
Info
Channel: Amit Nepal
Views: 92,746
Rating: 4.887218 out of 5
Keywords: apache, web server, apache web server, linux web server, web server in linux, centos, centos 7, redhat linux, linux server, linux tutorial, web server tutorial
Id: rCr3-YlL5S8
Channel Id: undefined
Length: 32min 42sec (1962 seconds)
Published: Sun Jul 07 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.