Search This Blog

Monday 22 August 2011

Installing Tomcat 7.0.25 on Ubuntu 11.10

1.  Installing Tomcat 7.0.25

1.1. cd ~/downloads
1.2. SOURCETOM=apache-tomcat-7.0.25.tar.gz
1.3. SOURCETOMWEB=http://apache.mirror.nexicom.net/tomcat/tomcat-7/v7.0.25/src/apache-tomcat-7.0.25-src.tar.gz
1.4.sudo wget $SOURCETOMWEB
1.5.sudo mkdir /usr/share/tomcat7
1.6. Unpack the source
sudo tar zxvf $SOURCETOM
1.7.Move the generated content of folder apache-tomcat-7.0.25 to /usr/share/tomcat7:
 sudo mkdir –p /usr/share/tomcat7
 sudo mv apache-tomcat-7.0.25/* /usr/share/tomcat7/
 
1.8. Delete apache-tomcat-7.0.25 directory:
 sudo rm –r apache-tomcat-7.0.25
1.9. Clean up the variable (and the compressed file)
 rm –f  $SOURCETOM
1.10.            sudo nano /etc/environment
Now let's set up the directories where we have installed Java in my case this is as follows:
JAVA_HOME="/usr/lib/jvm/ jdk1.0.7/"
JRE_HOME="/usr/lib/jvm / jdk1.0.7/jre/"
PATH=”…… :$JAVA_HOME:JRE_HOME”
1.11.            Configuring Tomcat users. The changes should be made in the file "tomcat-users.xml" directory tomcat7/conf. Command to edit the file:
sudo nano /usr/share/tomcat7/conf/tomcat-users.xml


The file would be as follows (add to the end of the file):

<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="admin"/>

<user username="ubuntu" password="ubuntu" roles="manager-gui,admin-gui,manager,admin,manager-script,admin-script"/>
</tomcat-users>

1.12.            Now we will attempt to start Tomcat7. First the server should be brought up with the following command:
sudo /usr/share/tomcat7/bin/startup.sh

The following output will be observed on console:

Using CATALINA_BASE: /usr/share/tomcat7/
Using CATALINA_HOME: /usr/share/tomcat7/
Using Catalina TMPDIR: /usr/share/tomcat7/tmp
Using JRE_HOME: /usr/lib/jvm /
jdk1.0.7/jre
Using CLASSPATH: /usr/share/tomcat7/ apache-tomcat \ 7.0.25/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar

Create the tomcat user and group:

sudo groupadd tomcat
sudo useradd –g tomcat –d /usr/share/tomcat7 tomcat
sudo passwd tomcat
sudo chown –R tomcat:tomcat /usr/share/tomcat7
 

1.13.            Automatic starting

To make tomcat automatically start when we boot up the computer, we can add a script to make it auto-start and shutdown.
sudo touch /etc/init.d/tomcat7
sudo nano /etc/init.d/tomcat7

1.14.            Now paste in the following:

#!/ bin/sh
# Tomcat7 Autostart Script
# Description: Provides Autostart Tomcat7 Servlet Engine
# processname: tomcat
# Default start: 3 5
# Default stop: 0 1 2 6
# Pidfile: /var/run/tomcat.pid
case $1 in
start)
echo –n “Starting Tomcat7\n”
sh /usr/share/tomcat7/bin/startup.sh
echo –n “Starting Tomcat7… done\n”
;;
stop)
echo –n “Stopping Tomcat7\n”
sh /usr/share/tomcat7/bin/shutdown.sh
echo –n “Stopping Tomcat7… done\n”
;;
restart)
echo –n “Restarting Tomcat7\n”
sh /usr/share/tomcat7/bin/shutdown.sh
sh /usr/share/tomcat7/bin/startup.sh
echo –n “RestartingTomcat7… done\n”
;;
esac
exit 0

The script should be made executable by running the chmod command:
sudo chmod 755 /etc/init.d/tomcat7 or sudo chmod +x /etc/init.d/tomcat7

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.
sudo ln -s /etc/init.d/tomcat7 /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat7 /etc/rc2.d/S99tomcat

sudo /etc/init.d/tomcat7 restart
Tomcat should now be fully installed and operational.

Useful Links:
Securing Tomcat Server
(OWASP Project)




5 comments:

  1. Superb guide thanks man

    ReplyDelete
  2. Great guide. Thanks a lot man.

    ReplyDelete
  3. anybody please help me
    where to save environment file ?

    ReplyDelete
    Replies
    1. Hello,
      You do not have to use environmental variables at all.

      Delete