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 http://apache.panu.it/tomcat/tomcat-7/v7.0.54/bin/apache-tomcat-7.0.54.tar.gz
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:
useradd -g tomcat7 -d /usr/local/tomcat tomcat7
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.
#!/bin/sh #Tomcat auto-start #description: Auto-starts tomcat #processname: tomcat #pidfile: /var/run/tomcat.pid #this path should point to your JAVA_HOME Directory export JAVA_HOME=/usr/local/java-7-sun case $1 in start) sh /usr/local/tomcat/bin/catalina.sh start ;; stop) sh /usr/local/tomcat/bin/catalina.sh stop ;; restart) sh /usr/local/tomcat/bin/catalina.sh stop sh /usr/local/tomcat/bin/catalina.sh start ;; esac 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
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:
<tomcat-users> <!-- 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"/> --> </tomcat-users>
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:
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: