I’m Patrick Bailey with whiteboard color calm today is August 14 2015 and in this video I’ll be going over how to install and setup Tomcat 8 on a bunt to 1404 this video would a lot longer than I thought it would as a result had to split it up into three videos this is the first part of this video if you want to go to the second part or the third part click on the linked links to those videos now so the first thing I’ll do is just show you that I really am on a bunt to 1404 there you go and next what I want to do is I want to install Oracle Java I don’t want to install open JDK and now you can’t usually do that simply through a sudo apt-get so you what you have to do is actually have to add new repositories from the web up da team and also there’s a little trick here that you can actually auto accept the license so what I’m gonna do the commands here in a row but actually you can take these commands in a run put them in a script somehow and that will auto that will you can remember in a non interactive way so that it would installed Oracle Java 8 and accept the Oracle license at the same time okay so I want to do a little bit of cutting and pasting in here because probably a little chance of me typing this all in correctly the first time no need to make this a little wider here so we can read it there we go so we echo this out this Oracle – Java 7 – installer except for excetera you see that and what that does is if you type that into this Deb comp set selections it will auto accept the license that Oracle will present to you when you install Java 7 so you set that and then you have to add the repositories so that you can actually get Oracle Java 7 and I’ll put these in the show notes or from a probe as a guest so you can copy them down rather than try to do verbatim what I’m doing here so you’d run those two and then you put in this let’s see there’s this key server there we go that’s good and then pseudo have – get update and this is kind of a fresh install on 1404 so let me take a second to update there we go so now we can do we need to install Java so – AB – git – why so you answer yes to the install man was that install Oracle Java 7 – installer hit enter and this should automatically install Oracle Java 7 and answer yes to any of the licensing agreements and there we go it should be downloaded and set up so now if I go to Java – version to check there we go I got 1.7 installed and it is set up right okay but how can you really tell this is Oracle job I’m gonna do that you do which Java LS and you see where this is actually linking to which is linking to that guy PTC alternatives Java and check that guy out and there you go so you can see eventually Java is actually pointing to user Lib JVM Jevon Java 7 – Oracle Jerry been Java there you go so it is pointing to Oracle Java let me clear this up get this back to more normal size there we go now where should we put Tomcat there’s a couple places you can put it one good place for referencing where you push it put things in UNIX I found this website path name comm FHS pub you can read it and this kind of gives you some historical things and where typically you should stick things so if you look down here their recommendation if you probably read this should be /opt

hat it’s a traditional place where you put in add-on application software packages so in this case you’d probably put it in you probably make a directory slash slash tomcat and that’s where you can put it but that’s not what I’m gonna do now typically nowadays I find myself working virtual servers cloud servers this and that so I don’t follow that tradition what I usually do is I’m usually mounting other hard drives so like an in Amazon I might mount a virtual hard drive in addition to the regular hard drive that’s where I put my extra information so I just make that simpler and so what I could do is I’d make it let me just do this so I do a sudo make directory I’ll do – P and then what I do is I put a project or a company name and then I would put in something like apps or logs and then those would actually be mounted as separate hard drives and so you know where all your customization would be on that server so in this case I’m not gonna actually mount extra hard drives on here because this is just for testing and showing you how to set things up but I’m gonna kind of follow that nomenclatures here I do 10 by 13 apps so I just make that directory and then I’d probably make a logs directory to and dependent how I wanted to set that up I just might mount that as one hard drive at the 10 by 13 or I might mount as two hard drives 2 by 13 apps and 10 by 13 logs but you do it how you want to do it it’s your stuff but what I’ll do here is I’ll put it in Tomcat there’ll be the Tomcat folder and even for the logs I’ll have all the logs going out to a logs Tomcat folder so real quickly I can show my structure let’s see if I have tree installed I do not like I said app that kid install tree I’m gonna see if we can do this so tree let me to clear free 10 by 13 and so there’s a structure I’d have so there’s 10 by 30 naps as Tomcat logs has Tomcat but you know let’s say I was gonna something you might typically do is stick an engine Xbox on this – or something else like that you might have like I have a server here at home or ninja axe and if I ever need to do it sits in front of other boxes as it routes traffic or some places and I’ve done this – you have Ingenix serve as your SSL certificate Handler and that will feed into Tomcat so if I was gonna do that I would do something like this and vlogs yeah let’s do tree again that’s good that’s hot there we go so you can see all the afternoon to the air all the logs we are there and those are what you would custom put on this box the main stuff on the box I would leave it where it belongs I wouldn’t mess with the normal of our logs or anything like that but for things that make this box unique I think it’s a good thing to do you can mount it I like another hard drive anyway that’s my opinion okay so just for cleaning things up I’ll go remove ten by thirteen so I just remove the Ingenix stuff there we go looking good okay now I want to run tomcat as the Tomcat as a tomcat user so I need to add a tomcat user so first I’ll add a tomcat group so there we go group add Tomcat and then I’ll add the user so user add s in bash Tomcat and I’ll make their home directory the Tomcat oh you know what I did this wrong yeah you know I don’t want to make it Tomcat I want to make it Tomcat 8 July 13 perhaps Tomcat too big move I know but the next poor guy who comes in here realizes joining Tomcat 8 I guess so alright ok better okay so I’ve added my group to Tomcat sorry I’ve added my let’s just shut this all over again so you know Tomcat user and that user needs a tomcat group so we’ll make the Tomcat

group can already exist we’ve got done that and then I want to add my Tomcat user given the bash script give him the group Tomcat and then set their home directory and I’ll set their home directory to be the apt Tomcat and then getting hard to read there okay so so you know let me try it again get a user add that fast then – dusty Tomcat start a new line there so it’s got the group Tomcat and then we want to set the dirt home directory which will set ABS Tomcat 8 and in the username is Tomcat there we go we’ve added our user now we need to download Tomcat Singh go to Tomcat Apache org slash download – 80 CGI and this should be Tomcat 8 downloads and then we want to do is go down here we want the tar.gz file let’s see that should Coria so right-click on that guy and copy the link address and then we want to do is come over here and I’ll go to my home directory and I’ll do a double you get and paste that guy in which looks really ugly ok make this bigger w get know how they get and they gonna fit there we go paste it in now that could change as well you probably ought to right-click on that and get the actual download location cuz it could move well no it’s uh it’s their mirrors so it’s gonna probably be different all the time okay so download okay that’s pretty fast okay now we want to untie it so we go sudo x ZZ f right yeah Apache Tomcat and then here – C tell it where you what location you want to untie it – and I’m going to show you something here if this is all I do and I’ll let it do it here what that did is it actually untargeted on cat ate folder but not but it had its own subfolder theirs and I have this Apache – Tomcat folder so which is a pain in the butt so I could go there and go in there and move the files but a better way to do that is this which I’ll show you here in a second remove that okay so what you can do so here’s the tower command but what you can do is you can add one more thing to it and I’ll start it a lot start under the line here so you can actually read it – – strip – components if I can spell write equals one and what that’s going to do is gonna strip out the first folder there or actually the first level of folders at other folders there toodles took them out right I’m gonna be saying that wrong but in this case the only one folder its gonna strip it out and it’s gonna put in that directory so that it accomplishes what we want so now if I do that we get our tommcatt looking like we want to in the location we want – all right now I need to change my permissions because I want that’s owned by a root right now so chain o our tomcat tomcat I’ll just do the whole 10 by 13 because everything in there right now is Tomcat anyway so hit that and that should go through recursively through all the files and folder and make Tomcat the Tomcat user and the Tomcat Group the owner of all that stuff and they are now next start the next thing I need to create a startup script give that guy okay and that’s a little more fun so there’s a people a few piece of information we need first of all we need to know the location need to set Java home so we middle the location of that so I will move this out here so you go well I do this before you know you watch Java and you get the o helps to be on the right box about that there we go leave the location of Java so there’s which Java and same thing I

did before Java and so now we know the location there so Java home is actually going to equal and I’m just doing this for reference so I can refer to it later I’m actually gonna put this in the script itself so Java home should be user live JVM Java Oracle Jerry in Java that should be our Java home and then we I want to create my own script so me and it dot d I’ll call it Tomcat 8 now for I go into this I want to show a few other Tomcat and knit scripts that I referenced got my own I’ve used before but I did a little more research and so I went looked on github gist and speaking of gist the other day I look at this and for the longest time I read just as guest guest until I finally realized it’s using gist like you get the gist of this cuz that makes perfect sense before I like guest that is a dumb name for what this is but just you get the gist of the code makes perfect sense I felt kind of dumb for mispronouncing it for like a year anyway so here’s some people here so there’s the lottos I referenced is and you can see the URL there I referenced rhodol but all fo 42 and you can see his URL there I also referenced a Germann and you can see the URL there you probably go into the gist repository and do a search and you can probably find these guys pretty quick by just searching searching for Tomcat or netd Tomcat and they have some good ideas I incorporated two of them and kind of route kind of fixed up the way I used to do it so anyway go check some more of those out cuz you may not like the way that I do it okay so let’s start coding here okay so first thing we want to do our Tomcat home which is gonna be 1010 by 13 apps Tomcat 8 and then log home and by 13 logs Tomcat 8 hid folder in VAR run Tomcat 8 now I just did a little research on this guy’s also people doing this into these scripts and I was kind of misunderstanding this for a little bit now var run is a great place to put these pit files because and I need be saying this kind of wrong it’s not a temp file but this folder does get updated programmatically on a reboot so if I put a pit file in there at top Pitts file the next time the machine boots that Pitts file will go away which is perfect because of the Machine reboots Tomcat is not running any way until the startup script is run and then a new Pitt file will be put in there so that idea that if you don’t delete a Pitts file it should be deleted automatically at a reboot so that’s a good place to put it right okay Pitts underscore file equals Pitts folder and Tomcat hidden and that’ll be the actual hit file okay let’s save that okay I’m gonna take a few seconds for a side journey here because here I am in vibe which relieves them in this case and I don’t have my syntax highlighting because when I started the file it didn’t know what it was now I could always I can shut close this file and open it again and the syntax Island will come through just fine but how do I I’ve never taken the time to see how I can reload the syntax highlighting I’ve just been lazy and closed the file and open up opened it up again but I’m sure there’s a way to do it so let’s see

we load them syntax I’m kind of went here two seconds ago but I did find this site and it looks like you can do colon syntax sync format start which I’m never gonna remember but I should so syntax sync from start it works and it didn’t do much syntax so from start okay I didn’t do anything hmm let me take a few minutes and see if I can figure this out okay it looks like I should have kept reading on so this guy said try e which I got to work in their console that I can remember e da okay okay so now going on so we’ve got that and we want to do I’ll scroll down to the bottom here so I’ll I’ll fill in some code here above here in a second but what I want to do is handle all the cases so if it’s starts I want to start and stop want to stop I’ll make those functions here in a second restart of course stop and then start and version which is pretty cool what you want to do with the version you can actually get the list you can list the version of Tomcat and it lists the version of Java waltz at it too so that’s the file it references and then I do return value and what that does is whatever exit code this gets back you can get that with a dollar sign question mark and if it’s an exit code zero you can do something with it so you can you can get the last exit code the exit code for the last command it was run there we go which I can use later just in case and hopefully catch on so we can do the usage zero start stop where you start status and version and I’ll put a I think already put it just up for this and if not I’ll put one up and link it in the show notes because this can be a pain to copy all this stuff right okay exit one I guess has a high do it and let’s do that all right how’s it look okay so there’s our statement now we need actually make the functions for these guys so start and these will be pretty short and sweet little few odds and ends you need to figure out and customize based on whatever you’re doing whether using fun too or you have some strange thing in there or yours in Cintas or whatever or male is it it’s time to the next distributions right I like a bun to they would check so I want to check if the pit folder now in this case the Tomcat 8 pit folder will be wiped out on every Ruby so you want to make sure when you first start it up you need to actually check if it’s there and if it is not make it holder and then

change the owner cuz often you’ll be running this script as as root so you want you want to make sure that this pit folder is owned by Tomcat and then so chooser and I’ve been using this command now which is kind of fun because really what I want to do is I want to run things as Tomcat so I’ve been using this command a lot so I switch user – space Tomcat so now which to the Tomcat user and then – see now as the Tomcat user run this command just kind of fun start a sh there we go and return value equals starter question mark well it looks like I got some notes on this let me this will be in the show notes to but let me I’ve got a URL that’s worthwhile just forget if you go this URL this is explaining that return value so there it is dollar sign question mark expands the exit status and there’s other interesting things that you can get you know we’re used to getting 1 & 2 but you always kind of forget about zero and there’s some other in from interesting information here so there’s leave RL okay so there is our start and then stop see echo – mmmm stop being Tom can’t switch to user – Tomcat – C and Tomcat hmm then shut down – I just – force and same thing get the return value equals a star dollar sign question mark there we go and then status I say if if there’s a file if my Pitt file exists then head equals cat did file just retrieve the actual pit number Tomcat is running process ID okay there we go and then house echo Tomcat is not there we go and I think that should do it so we get our start our stop the restart the version ok looks right so I’ll save that mm-hmm ok so now you just need to add the service so I can do sudo change bond well thank you shirts executable ok there we go and then I need to add it so that it will start when I when I when the computer starts up and stop when I reboot or shut down and so simple way to do that is to do that use the update dot our CD command Tomcat 8 and use defaults and if we do that what it’ll do is it’ll update all the commands in the run levels and that’s typically what you don’t want you know if you want to tweak it you can tweak it but that’s fine for now now let’s test it I haven’t slept tommcatt the whole way yet but I can do it one one of two things I could do Tomcat 8 and I could do status oh I got a syntax error I did it to do of course I got syntax our I had to mess something up with all

that right let’s see what’s wrong here I should exit in there too so I don’t have that return value but that looks ok I’m not seeing the forest for the trees right now I’ll just comment do this phone number let’s see 2800 3657 there we go you know that looks like it there’s my real culprit there we go I spelled case wrong supposed to eat yeah yeah tell me something else isn’t it ok so I go up there and through those okay status syntax error okay doesn’t like we’ve got version so there here’s the cool thing about version there’s your tomcat version 8.0 and there is okay I can’t see there we go there’s our job at 1.7 and there you go JVM vendor Oracle Corporation perfect and if I do start is it gonna start yeah it’s not I’m 14 space there dinner yeah there you go so those we started I don’t care right now cuz I’m gonna fix that anyway I don’t like the way it’s gonna run let me stop it Caleb fell cuz won’t kept I don’t need to worry about that right now but why why is my status not working I know there’s someone out there in YouTube land who can see the problem and it’s probably driving them nuts right now this in a space huh there we go let me try that there we go alright so start and stop need to be setup but they’re kind of working restart what course would work to the level of starting to stop her working status is working version to working so I think thingy okay good so I’ll put that up on guest guest I just said it again just I’ll put it up on just as a gist I’m github to go to the second part of this video click the link here thanks for watching I hope this video was useful to you if it was please give it a like to subscribe just click the subscribe button also you can follow me on twitter under the handle at white board coder view any code I may have put up as a gist on github under the username Pat man Denver or check out my blog at white board coder com