Apache Web Server with Django Framework

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay in this video we will configure um apache uh to work with uh the django framework okay so in order for us to actually get that up and running as you can see right now in a previous video we set up apache to execute python scripts such as this guy here and we did that so we would have to update the apache configuration file and just basically we're going to do we're going to unset we're going to remove dark custom configurations because we're going to install a module to actually do this for us well it's gonna allow us to actually execute um python files especially within the django framework so i'm gonna remove that exact cgi command um and what else we had we had the uh let me just do a add handler um where's my handler let's go down we're looking for that to remove the dot py i billy there he goes right here we're gonna remove that guy and we should be good um okay so that was about it save that i'm not gonna restart the system yet um so what are we going to do first is uh we're actually going to create a virtual environment a python virtual environment so i'm opening up a terminal and i'm a cd into my folder where i creates all of my um where i prefer to keep all of my code which is a code folder within my c drive and there's nothing in it currently um the reason why we want to create a python virtual environment because we want to keep separate all the add-ons or the modules the packages we want that contained within its own folder we don't want it so if i were to do a pip freeze this is globally this is within my computer itself you will see i have a couple right so i don't want to keep adding adding more onto my computer itself i want to keep it separate so in order to do create a virtual environment i just type in python dash m and then this is the virtual environment executable i'm using and then give it the the name of the folder you want it to you want the virtual environment to live in in this case i'm just going to name it the same as the command so i'm just going to name this going to be my virtual environment folder and i'm going to hit enter okay um now once that is complete i'm going to cd into it and then activate it okay so seating into vn um we can just go into vm and then scripts activate okay so now we were actually in it and you could tell because you see it says right here vn vnv okay so if i ls into it you just see there's nothing in there right um we're not going to touch none of these files in here um now the next thing we're going to do is actually um attempt to install the mod wsgi package the reason why i say attempt is because we're going to receive an error because we have to set um an environment variable to point to the apache web server the directory where the apache web server lives in um in this case i'm just going to want to honest to actually run the command so you can actually see the error and it will actually give us that that command that we need to point to the variable to create the variable that is okay so i'm just going to do a pip install mod underscore ws gi right okay um yeah and also this will give us a warning as well to um let us know that we have to upgrade our um pip um so this is the warning here okay so you're saying that i'm on a lower version 20.2 and there's a 21 that one zero but we really want to care we really care about this runtime error okay when it says it's run timer no apache installation can be found we have to set the mod wsg apache route to its location okay so i'm going to copy this okay and since i'm in the windows powershell as you can see up here this terminal is using windows powershell so if you are not commit just a plain old command prompt you would use set to create um an environment variable i'm in apache i'm sorry in the powershell we will use dollar sign env to create the uh the environment variable and um i just paste that that's the command and then you just have to put the equal and the location of your apache installation in my um case um i have apache right in my in the uh the root of my c drive so i'm just going to copy that paste it in and hit enter okay so now i have that environment variable and i'm gonna go ahead and upgrade copy the scripts i'm gonna upgrade the um pip installation so once that has been upgraded the pip um since it's quick i'm just gonna rerun the command so i'm gonna do pip install um space on mod underscore wsgi okay and that should be a very quick installation um next we're gonna actually run a command that's included with this package okay so if you do a pip freeze you would actually see this is the only package that i have installed okay so now i could just run the command mod underscore ws gi dash express without giving them any parameters and it's going to tell you the two commands that we have access to and which is module config and module location so i'm just going to copy the module config okay i'm going to press up and i'm going to press enter okay so now you see this is we have load module and it's pointing to the module and we have the python home which is pointing to this and which we're going to change this because this is not we don't want this as a python home so i'm just going to copy that okay i'm gonna paste it back um at the bottom of my httpd conf file which is our apache configuration file okay save that um now the thing is um if i was to run this right now we will receive an error okay and i know this for fact let me just clear out errors just make sure uh we have no errors okay i just want to clear any errors out um and why did i not okay apparently that was the first time that happened to me all right so we're going to um we're just going to run this as an admin okay so i'm just i just want to clear it out it's not it's not required um you can just go i just want to make sure that the arrows the logs is cleared there are no logs okay okay i'm just going to clear that out and strangely it's not giving me it's like if it's read only for me all right so if you get it i'm not going to spend too much time on that um so this will give me an error if i try restarting the system because it's not going to um understand these commands um so what we would have to do is we would have to actually load or add some more um some more um variables that's pointing to certain locations okay so the first one above here is going to be load file right so basically this is going to be a file that's pointing to a dll um and which is going to it's a um the python dll and it's but um let's go into that folder uh what is that users um oh i'm sorry it's not users it's probably program data this is where i actually installed uh no no it was users i'm sorry it was users um local i mean the name of your your login user or this is where i stole it so you would actually look for the location of the python you installed it um in which my case was uh pac uh programs python python 39 and then this is my python installation okay so i'm going to copy that and what we what we're going to actually include in this file is this right here this python39.dll yours may be different depending on the uh the version of python you have installed okay so i'm going to now i'm just going to copy this name i don't feel like typing okay um all right i'm going to save that so now we have the load file and we have this um home directory python home um in this case we don't want this to be the home we want to point it to the actual the same location that i have the programs we want that to be pointed to it as well so i'm just going to do here oops apparently i didn't copy the path all right so let's get this so this is going to be the home directory okay save that so initially um this will work it will it will it would allow you to restart the apache without any errors but let's go forward and add the um other i think believe this other two um we would have to install provide the path the wsgi python path and this wsgi script alias um okay so oops so it would be the wsgi um what i did ws gi okay python path okay so this path would just take one parameter and that's going to be the package path the site packages the python site packages path so that will be we're going to point that to our virtual environment the virtual environment path so when we created the virtual environment okay so inside our code this lib site packages so this is what we're going to point it to okay and that's all we know we might we have to add a space okay so that's all we require for that okay so next one is the script alias so ws gi script alias okay and just take two parameters it's going to take the the directory um or the path that we want it to be and it's going to be the root so we can just place a slash and the next one will be the location okay so this is going to be the location of our wsgi file okay and this point we can't point it to anything right now because we don't have that ws you if i when i want you may say what what w we don't have a wsgi file right that's coming from python okay i'm sorry that's coming from django so that wsgi we would have to modify it a bit but it's coming from django it's included when we create a um when we create a package i'm sorry a project and um and then where we create a um an app from just from django okay so um so what we're gonna do next step we're going to just basically um install the django um package and from there then we're going to have to update the configuration file or the wsg wsgi file to actually point to um so it'll allow us to give us access to the to um um the the actual folder the directories that we need to execute it within python apache okay so i'm going to go into my project and this is my project yes so go and bring up your terminal and what we're going to do we're going to because we we don't have pip let me see pip freeze we don't have django installed yet so we're just gonna do a pip install okay django okay and once that's installed we would have access to a command called django admin and that's gonna allow us to actually create the project once we create the project we're going to cd into the directory and we're going to create an app okay so i'm going to run django dash admin um start project and the name of the project right so name project i'm just gonna name it back in so this is gonna be the all the software i mean all the code on the back side of it okay which is going to be python so i'm just going to hit back in press enter and it was created you see we have the backend folder okay so the next one we have to succeed answer that back-end folder and then now we're going to use python because the reason why we're going to use the python we're not going to use django admin because if i do a ls we're going to utilize this file manage py now this file is used extensively within the django framework um we're going to run python manage py okay and from there we can just um create the app right so we're going to say start app and then we space and then we give it the name of the app and i'ma call it base whoops i'm going to name the app just base this is going to be the base the root of my app this is where i'm creating my custom code inside this folder okay and that was it so now we would have access to the um wsgy um wsgi dot pi file that i was referring to earlier um so in order to do that let me bring up my uh uh i'm gonna save this yeah i'm saved i'm gonna close out of it for now i'm gonna open it up because i have to add on my open folder um go to code then all right so this is going to open this folder we're going to open in code or whatever your editor is and back in and you see right here wsgy wlgi.pi so this is the file that we're going to point um let's open up our apache config file so we're gonna have to um add that in here so i'm gonna go into uh so it's gonna be at it's gonna be at the very bottom right so this we're going to point it we're going to point that to here once once we actually get it um so it's going to be basically back and back end okay so right now we're not pointing anything to it so um we can just go into here then let's go back in back in and this is the path okay you can copy that let's paste it and then wsgi dot py save it okay now we can go back to that and we can just start making some changes to this file so we're gonna um basically um import um sys okay oh what is this uh this is a an error for my laptop okay so now we're going to just say uh we want to import the path so just all these imports that i'm importing these modules that i import in these packages it's included with um python this is part of python okay so i'm gonna do path lib okay import path okay um and that's it from there there's so this is these two that we require and then from here let me go believe beneath this guy um then we're going to create a variable that will point um to a path that would be um it's going to take the first file in that path right um let's see so um what what name we could just give path home okay equals um string okay and then within the string we usually call the path and then here we can give it the magic method on underscore underscore file and then that's going to call on the outside dot append parents plural and then we're going to take the first one the second one in there actually because it starts you know zero one two three um and that's it for that and now we could just create a conditional state we could just write a conditional statement so you could just basically say if the path if the home if that location um is not in the system path do something okay so basically this is on one time thing you're just gonna do this you could probably copy this into some a github or something you could just copy and paste it so you would never have to do it again um manually um so if um path home what happened to my uh this path home okay um is now i would just use human read i would just say not um sys dot path okay uh shortcut keys is messed up okay um then i would do cis cis dot path um we're going to append okay so we're going to append the home the actual variable that we created okay so and then we get the space so that's all we did we just it was just these two and we imported something that was it that's it we could close this um no need to what was it was an error here somewhere oh i thought i seen there um cis what's going on why you don't like this cis um system path oh i'm sure you've seen a path a there's no all okay just mine don't mind is it's the um visual studio code it's not defining this but that's fine it is no errors on there um so that's it basically um now we would just have to make some more changes um in our um apache config file so basically we undid everything that we did in the previous video so we can actually execute scripts um now the only thing that we would have to do is we're going to have to go into our directory and we're going to have to point uh our directory when i say directory our um document directory that is and we have to point the directory to our virtual environment and which right now i'm doing in a dirty way this is like an extremely dirty way normally if you would create virtual virtual apache directories and you will work well for that so you can have multiple websites and such right but i'm just doing it i'm just killing my current directory and then but you can create virtual and it'll work the same way if you create a virtual directory okay so um so i'm looking for the virtual directory i'm sorry my document directory uh probably passed it let's go see it um server admins here we go okay so underneath that so right here um that was online 252 so i won't forget it so i'm just going to copy this right because it's going to be the back end backing this is my this is the path 252 right okay so we're going to replace this okay so it's no longer going to go to point it to the apache folder instead it's going to point to um my virtual directory which is the back end backend so it's basically just pointing to this guy this directory here okay and that's it for that and then underneath that we won't have to create a files okay and then make sure i close it okay um so basically and this is going to point to that wsgi file that we edited earlier wsgi dot pi okay okay and then go down and then from here we're just going to require all granite so require all granted save that so that's all that's required okay so we added we changed the directory to point to our virtual environment back in back in so basically this guy here so you got your virtual environment you went into your project and then you went into the project again so this is make sure it's pointing to where you have your wsgi file that is located in here okay and then we require all granted okay so now fingers crossed let's uh restart the um apache service and we should see um the django um um splash page the default django splash page okay so let me get rid of this i'm just gonna hit localhost and he's saying it works let's refresh so it should point to just django there we go it's pointing to django and you can see so this is actually the back end of django um and that's uh it's pretty cool if you know and it's in and it's this is apache that's running instead of the django development server so um we can make some changes in here i believe if i recalled um we got to go into our app so back in the base views oh there's nothing in our views um hmm how do you make a change to the change just pointing to the face well it's not important but we can um so let's let's let's just try that since we already have it up and running so let's change this let's let's let's let's in the next video let's make some changes so we can actually see it up it actually have see something working but as you can see we django is running in apache web server so um in the next video we could probably make some changes let's let's create like a front end whatever zone some front end some some javascript and um so you can talk to the back end which in this case this is django right so we're just gonna pull information from python and it's gonna bro bring it up on the browser okay so i'll see you next video
Info
Channel: Joe
Views: 853
Rating: undefined out of 5
Keywords: python, apache, Django
Id: lo-pmgu8TcI
Channel Id: undefined
Length: 24min 42sec (1482 seconds)
Published: Sun Apr 11 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.