How to install Tomcat 7 on Debian


This Article describes how to install Apache Tomcat 7 on a Debian (Lenny) OS in 8 easy steps.

For this HowTo to work smoothly you must already have Java installed on your machine. In case you haven’t Java installed on your machine, there is anoter HowTo for this Task on my Blog.

1. Download it!

The first step is to aquire Tomcat 7 by downloading it from the Homepage. This is really easy, I used wget to download the “apache-tomcat-7.0.54.tar.gz” archive into my /temp Directory. This should look something like this:

# cd /tmp
# wget

2. Unzip & Move

Move the package to it’s permanant location and unzip the package into its own folder.

# mkdir /usr/local/tomcat
# mv apache-tomcat-7.0.54.tar.gz /usr/local/tomcat
# cd /usr/local/tomcat
# tar -zxvf apache-tomcat-7.0.54.tar.gz

3. Create “tomcat” Group & User

Next you need to add a new group and a new user to your system. This will be the user and the group under which the Tomcat server runs.

1. To add a group called “tomcat” you simply type:

groupadd tomcat7
2. Now you have to create a new user called “tomcat” (useradd tomcat) who belongs to the group “tomcat” (-g tomcat). You also should set the home directory of that user to the directory where you moved the Tomcat server in the previous step. In this case that would be “/usr/local/tomcat” (-d /usr/local/tomcat). So you should end up with a statement that looks something like this:
useradd -g tomcat7 -d /usr/local/tomcat tomcat7
3. Now you should also add the user to the “www-data” group. This group should already exist. You do that by executing the following command:
usermod -G www-data tomcat7

4. Create INIT File for Tomcat

Now you should create an INIT-File that makes it possible to start, stop and restart your Tomcat Server. This file must be located in your “/etc/init.d/” directory. You can use the following command to create a file called “tomcat” and open up that file in an editor.

vi /etc/init.d/tomcat
Now you should add the following lines into the file an save it:

#Tomcat auto-start
#description: Auto-starts tomcat
#processname: tomcat
#pidfile: /var/run/
#this path should point to your JAVA_HOME Directory

export JAVA_HOME=/usr/local/java-7-sun

case $1 in
  sh /usr/local/tomcat/bin/ start
  sh /usr/local/tomcat/bin/ stop
  sh /usr/local/tomcat/bin/ stop
  sh /usr/local/tomcat/bin/ start
exit 0

5. Adjust Permissions of INIT File

Since you have to execute the tomcat file, you have to assign the correct rights for the file to be executable.
This line should do the trick:

chmod 755 /etc/init.d/tomcat

6. Make Tomcat auto-start on boot (optional)

If you want the Tomcat Server to start every time the system boots up you can use the “update-rc.d” command to set a symbolic link at the correct runlevel. For the “tomcat fle” this looks like this:

update-rc.d tomcat defaults
Now the Tomcat Server starts automatically at system bootup. This step is optional you can always start your Tomcat Server manually like this:
/etc/init.d/tomcat start

7. Modify Tomcat Users File

We are almost there! In this step we need to add a user in the tomcat-users.xml. This user is used to gain access to the Tomcat Manager Interface in the next step. So open up the “tomcat-users.xml” file with any editor you like:

vi /usr/local/tomcat/conf/tomcat-users.xml
There is a <tomcat-users> section within that file. After the installation this section should only contain comments and look something like this:
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>

Now all we need to do is add a new user by adding some new lines before </tomcat-users>.

<role rolename="manager"/> <role rolename="manager-gui"/><role rolename="admin"/><user username="admin" password="tomcat" roles="admin,manager,manager-gui"/>

This user will be used to access the Tomcat Manager Interface in the next step.

All there is left to do is to restart the Tomcat Server to make him recognize that the “tomcat-users.xml” file has changed and that there is a new user with the name “admin” and the password “tomcat”. This is how you restart your Tomcat Server:

/etc/init.d/tomcat restart

8. Test Tomcat Manager Interface

Finally we can check if everything went right. If your Tomcat Server runs on your local machine your can access it via the following adress:


otherwise you have to replace the “localhost” part with the IP adress or name of your server. This could look like this: