Apache Basics Tutorial | How To Install and Configure Apache2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
apache is a tried and true piece of software that has stood the test of time and its install base is huge you can find it on all kinds of linux and unix servers alike it's a great piece of software so i guess it makes sense that it's so common and of course you can utilize it on the lynnode platform and in today's video i am going to show you some examples of not only configuring apache 2 but also installing modules as well so let's go ahead and get started [Music] alright so for this tutorial i've already gone ahead and created a lino that i've cleverly named apache tutorial this particular node is running ubuntu 2004 as you can see here and it's actually ready to go we have the ip address right here and if i copy this and then paste it over here into this new tab you'll see that nothing will happen why because it's a fresh linode and apache has yet to be installed if i go down here to the terminal i can connect to that linode via ssh it's a fresh node so all we have at the moment is the root user i'll paste in the ip address right here and there we go now before we get started there's a few things that we should do a little bit of housekeeping if you will first of all we should run apt update to make sure that our package index is completely up to date and i didn't need to use sudo because i am logged in as root and right here it's telling me that 67 packages can be upgraded so we'll definitely want to take care of that right now so i'm going to run apt and then dist hyphen upgrade which will install all of the updates that were found by the apt update command press enter and this might take a moment so i'll press enter and then i'll be right back as soon as this is finished all right so all of the updates have been installed so we should be able to continue along and the next thing that i recommend that you do is update the host name because right now the server is called localhost which isn't very descriptive is it so we want to give this server a name that will match its purpose and there's a few files that we will want to edit so we could use nano or whatever your text editor of choice happens to be and the first file we will edit is etsy hostname and as you can see it is currently set to localhost just like it showed in the command prompt and then right here you can give your lynode a descriptive name if you have a domain name for example you can go ahead and type that right here for the name of the server but you don't actually have to have a domain name for this example you can call the server whatever you like what i'm going to do on my end is give this linode a name that matches its actual name on the dashboard so i will call it apache hyphen tutorial i think that's good enough so if you aren't already familiar with nano you can hold control and press o to save the file and then enter and then control x to exit out the second file that we will need to edit is etsy hosts and what we can do right here is add a new line i'll just do 127.0.1.1 and then tab over and give it the same name here that you gave it in the etsy hostname file so in my case i will add apache tutorial right here just like i did in the original file and we'll save it and it out now at this point i recommend that we reboot the server because not only did we give it a new name we also installed all of the updates as well so here we can go ahead and just drop this down and click on reboot and then back here on the terminal i should be disconnected any moment and my connection was dropped so it is rebooting and i'll just give it a moment to go ahead and reboot and as soon as it comes back up then i will connect and we will continue so let's see if enough time has passed and it looks like it has and there we go server is back up and running as you can see it's been up for zero minutes so it just started up and we also see the host name right here which in my opinion looks a heck of a lot better than simply showing localhost so now that we have all of that set up we can go ahead and continue so let's go ahead and get apache installed after all we can't learn how to configure apache if it's not even present on our linux so to do that we will run apt install apache 2 apache 2 dock and also apache 2 hyphen utils and then we'll press enter and i'll accept all the defaults i'll press enter again and that was pretty quick so we can check the status of apache just to make sure that it's running and it's healthy by running system ctl status apache 2 and then enter we can see right here that it is active and running it's also enabled and what this means is that when this linux starts up apache 2 itself will automatically start as well so you don't have to go in and manually start this every time you reboot the server now if for some reason it shows disabled instead of enabled which is extremely rare you could run systemctl enable apache 2 just like that i'm not going to do that because well it's already enabled if it wasn't running then you could do system ctl start apache 2 to actually start the process if for some reason you need to restart the apache 2 process then you could do so by changing that keyword to restart but the problem with that is that will also disrupt anybody who is trying to access your web server it'll actually drop all of your users so sometimes it's better to reload if you can but anyway it's running so we shouldn't need to do anything back up here in my browser if i go back to this tab right here previously i tried to enter the ip address here just to show you that it wasn't working because well apache wasn't installed so i'm going to remove this part right here because this isn't actually https i should be able to press enter here and sure enough we see the default apache 2 web page right here and this is accessible from anywhere in the world with internet access at this point we now have a publicly accessible apache installation ready to go but how do we configure it well let's take a look at some examples and i will show you now to configure apache there are several modules that can be installed that will extend its functionality now which modules you'll need to install all depend on what you want to host with apache if all you want to do is host a single static web page you don't need anything else you already have everything you need you saw the default apache page you could just replace that with your static page and then you'd be all set and ready to go there'd be nothing else for you to do some applications that you can run that can be hosted via apache for example next cloud wordpress and so on they each have their own requirements and their documentation will tell you exactly which modules you will need to have installed so what i'm going to do now is give you some example modules that might be some that you'll need and i'll show you how to install those now one thing that we can do to get a list of some of the modules that are available is we can run aft search then lib apache 2 hyphen mod short for module i'll press enter and there's some here that aren't related but if we scroll up we get all of these packages that start with lib apache 2 hyphen mod hyphen and then something at the end and usually you can glean from the name what exactly it does so for example we have lib apache 2 mod python so installing that will actually add scripting support for python once you've found a module that you want to have installed then all you have to do is install the package for it which is as simple as apt install and then lib apache 2 hyphen mod hyphen and then whatever it was so for example if i wanted to add python support i could just simply type this package name right here and press enter and then enter again and that will give us python support another popular example is i could change python to pearl 2 if we want to have pearl support and easy enough i'm just simply installing yet another package now when it comes to ubuntu at least there's a very specific way where you can enable or disable modules because just having it installed isn't generally enough although ubuntu does try to automatically enable any apache modules that you have installed so you just saw me install support for pearl and python so those should both be enabled by default other distributions are a bit different make sure you check the documentation but the ubuntu specific command for enabling a module after you install it is a2 and mod just like that so i'll press enter and it actually gives us a choice of which modules we want to enable now notice i didn't install all of these i only installed the pearl and python module there's a lot more here that we can actually enable so if there's something here that your website technology requires then you can use a2 and mod to enable that particular module you could type the name of the module after the a2 and mod command you don't actually have to look at the entire list if you already know the name of the module you want to enable and we can also see that python is on this list so i'll just go ahead and type that and it's telling me that that particular module was already enabled so just because you see it in this list when you go to use the a2 nmod command it doesn't mean that it's not enabled it's actually just showing you a list of all the modules that you have installed if you want to disable one it's actually pretty easy you could do a2 dis mod for that and i'll press enter here and here we actually are getting a list of modules that are enabled and you can see that both pearl and python are on this list so if i didn't actually need pearl like i thought i did i could remove the package or i could actually just use a2 disk mod to disable that module so i'll press enter and then it tells me that the module is disabled but it also tells me in order to finish disabling that particular module i'm going to need to restart apache 2 so just keep that in mind a simple reload of apache 2 won't really cut it a reload is a lot more graceful than a restart but at least you'll know that you actually do need to restart in order for that to take effect if i wanted to re-enable it i could do a2 and mod just like before but i can actually give it the name of the module right here without looking at the entire list and now it's telling me that pearl is now enabled but again it's also telling me that i need to restart apache 2 for the changes to take effect now apache is actually able to host more than one website on the same server and in order to facilitate that there's a feature called name based virtual host and to facilitate that ubuntu has two commands that are specific to that distribution a2 and site as well as a2 disk site as you can probably guess a2n site enables a site and a2 disk site disables a site but how do you even know which sites are even installed on your web server so that you know what you can and can't enable or disable so if you have a look at the etsy apache 2 sites available directory you can see all of the config files that you have available right there and we get these two by default we have the default one on the left and we have the default ssl version on the right so what we can actually do is a2 disk site and let's disable one of the default config files so now it's telling me that that particular site is disabled so to finalize that it also wants me to run systemctl reload apache 2 so it actually tells you whether you need to reload or restart based on the nature of the change which is pretty helpful so i'll press enter so now we have that site disabled and the reason why i've disabled it is because i'm going to show you how to create a new one or a custom one so for that we're going to run nano etsy apache 2 sites available and then example dot net dot co and f and then enter and then here i've pasted in the config for the example.net website and just to go through this real quick the virtual host is listening for connections on port 80 which is the default we have the server admin which is the individual that is responsible for this particular website then we have an email address for that individual we then give the server a name and we're going to call it example.net then we also have server alias which is the same as the server name but it has the www at the beginning and the reason why we're doing that is because we don't know if the user is going to type example.net or www.example.net we want to make sure that regardless of which of those two urls the user types they are directed to the appropriate website which is why we have two entries for the domain we also have the document root right here which is pointing us to this directory it doesn't exist yet but we will be creating that shortly then for the error log and the custom log we are pointing those two files that are in a custom directory and the directory for these that doesn't exist either but we will be creating that shortly so it's pretty straightforward so i'll go ahead and save the file then i'll exit out so now what i'm going to do is create another virtual host file to illustrate the fact that you can have more than one website hosted on the same web server so this is the command that we used to edit the original virtual host file and i'm going to change this to example.org and again i'm going to paste in the code for this example right here it's essentially the same as the previous one except instead of example.net it says example.org so that's pretty straightforward and another thing that i want to show you as well hypothetically if we wanted to enable scripting support for say perl we did install that package earlier there's a few more lines of configuration that we can actually add to this file what i will do is paste that in right here and i like to keep everything neat so i'm going to make sure that everything is lined up and now we have a few lines of configuration here that will enable pearl now i'm not going to actually show you a perl example but i did want to show you an example of adding additional lines of configuration that would be required to fully enable a scripting language such as perl other scripting languages will have different lines of code that you might need to add this is just an example but anyway i'll save the file and then exit out now one problem with those virtual hosts files though is that the directory that the document root references the directory doesn't exist for either of those virtual hosts so we will need to go ahead and create that and as you see here we are simply making a new directory the dash p option make sure that all the parent directories are created as well if they don't already exist and in this case we are adding the directory for the document root for the example.net website and then similarly we also need to create the directory to store the log files as well that's another directory that was mentioned in the host config file and then we need to do the same thing for the example.org website as well and now we should have the directories for each of the document roots as well as the log directories so now that we have added two config files for two websites we will need to actually enable those websites otherwise we will never get traffic and no one will be able to access them as mentioned earlier we have the a2n site command that facilitates that and then you type the name of the website that you want to enable so for example example.net and it's telling me that it did indeed enable that site i'll need to reload apache 2 for that to be finalized and i should also enable the second virtual host as well so now we have two websites that are being hosted on this server now if you want to actually receive traffic on the web server the domain name will need to exist and the a record will need to point to this web server in order for this to work but you can change example.net and example.org to whatever your domain names happen to be update dns and after dns propagates you should be good to go but anyway i'll just run systemctl reload apache 2 to make sure that everything is properly enabled and well that was pretty easy now those are some simple examples of name-based virtual hosts obviously you will need to have some sort of website files installed in the directories that we've created so for example you could copy the default website file for the apache default web page into those directories as a test but it's beyond the scope of this particular video because example.net and example.org are hypothetical websites the point was to show you how to actually set that up and well i've done that but there's other examples in the documentation that this video is based on if you want to see even more examples of how to configure apache so if you want to learn more definitely check out that article when it comes to apache there's no shortage of different ways that you can customize it as well as modules that you can install to extend it even further so we've only begun to scratch the surface in today's video but i hope it was helpful as always click that like button if you like this video because that lets youtube know that you want to see more linux content just like this and make sure you also hit that subscribe button because we have some awesome content coming very soon so thanks for watching [Music] you
Info
Channel: Akamai Developer
Views: 287,971
Rating: undefined out of 5
Keywords: linode, linux, cloud computing, alternative cloud, linux server, open source, sysadmin, apache, apache 2, web server, webserver, linux web server, linux tutorial, web server tutorial, apache 2 basics, apache basics, system administration, apache virtualhosts, command-line, web hosting, apache server tutorial, apache configuration, install apache linux, apache server status, host sites on apache, apache server setup, apache web server, apache linux tutorial, apache status
Id: 1CDxpAzvLKY
Channel Id: undefined
Length: 20min 45sec (1245 seconds)
Published: Wed May 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.