Setting Up Tomcat Server on Ubuntu

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies. This post explains the installation and configuration of Tomcat on Ubuntu. I assume the reader to have basic knowledge in Ubuntu.
From Terminal/SSH :
  1. Run update
    sudo apt-get update
  2. You can see the list of tomcat packages by issuing a search command
    apt-cache search tomcat
  3. Install Apache Tomcat using the following command
    sudo apt-get install tomcat7
  4. Install Java
    sudo apt-get install default-jdk
  5. Now you have to set environment variables in bashrc
    sudo nano ~/.bashrc
    Append the following to bashrc (Omit contents after //)
    export JAVA_HOME=/usr/lib/jvm/default-java
    export CATALINA_HOME=/usr/share/tomcat7 //Or tomcat's directory
  6. Reload bashrc by
    . ~/.bashrc
  7. Now start tomcat by
    sudo /etc/init.d/tomcat7 start
  8. If everything was successful
    • sudo /etc/init.d/tomcat7 status
      will show a message, "Tomcat Servlet engine is running with pid [some pid]"
    • Typing server ip address:8080 in your browser will show default response (eg: http://123.456.78.90:8080)
    • Create a index.jsp at /var/lib/tomcat7/webapps/test and write in
      <%= "Hello" />
      Now typing in http://123.456.78.90:8080/test/index.jsp should show "Hello" (without quotes)
  9. If you want to change the default port (8080), you have to edit /etc/tomcat7/server.xml
    sudo nano /etc/tomcat7/server.xml
    Look for
    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
    Refer Tomcat official site for more information
The /var/lib/tomcat7/webapps/ is where you will put your app files. In the list from apt-cache search tomcat you can find helpful stuffs like sample apps, docs etc. You may optionally install these using sudo apt-get install [package] command

No comments:

Post a Comment