Monday, 25 August 2014

Installing Tomcat on Arch

Tomcat is an application server that can be used to run your JSP, servelets etc. In this post i am going to show you how to install and run applications on the server.

Installing tomcat8

$sudo pacman -S tomcat8

Different versions of tomcat is available in the arch repository. tomcat8 is the latest release version.
 After installing tomcat8 on your arch you can now start tomcat using the following command.

$sudo systemctl start tomcat8

You can enable tomcat to start on every boot by the command

$sudo systemctl enable tomcat8 

by enabling, tomcat is going to start on every boot. tomcat on default runs on port 80, so if you have another server also running on port 80, Tomcat will not start. 

NOTE: Glassfish server used by NetBeans uses port 80. So if you are working on Netbeans Glassfish server wont allow you to start tomcat.

Now your tomcat is up and running, you can test it by opening a browser and typing 

localhost:8080

This will open up the home page of tomcat. you can additionally change settings from here.

Running you first webpage on tomcat8  

Now, to run normal web pages on tomcat you first have to create your webpages. HTML can be written in any of the editors in linux. My fav are sublime and blufish editor.

After you are done writing your webpages, you can upload them to your tomcat server.  For that you should go to 

$cd /usr/share/tomcat8/webapps

this directory has all your webapps. now create a directory . 

$mkdir MyFirstWebapp

cd into the directory . Now this directory is going to contain all the webpages that you want in your website. so copy all the HTML files to your webapp directory. you can also issue the command..

$sudo cp /path/Of/Your/HTML/File/ /usr/share/tomcat8/webapps

Now you can can try your awsum website out by running tomcat. all you need to do is, 
1. Open a browser
2. Type is localhost:8080/MyFirstWebapp

this is going to open the index.html file present in the MyFirstWebapp. If you want to open a specific webpage from the server you can specify in the address..

localhost:8080/MyFirstWebapp/MyWebPage.html

And you are good to go.......