I had some trouble configuring Tomcat server for Java Server Pages(JSP) to work on a particular port on my first install. This post will be brief because there isn’t much work to get the basic configuration going on Debian Squeeze. Basic commands for installing tomcat6 is:
# apt-get update
# apt-get install tomcat6
First command fetches new package list from you repository, and the second fetches tomcat6 package and installs it. Now you have your tomcat6 server installer and running. Tomcat6 is configured to use port 8080 by default. You can verify that it’s up and running by going on to localhost address. Another way, the GUI way, is to fire up synaptic and searching for tomcat6 package then installing it. Same result is expected. I have apache2 installed also, but I wasn’t going to run both of them at the same time so I wanted to switch tomcat from port 8080 to port 80. Stuff became confusing since I thought all I needed to do was edit some configuration files in /etc/tomcat6. I was wrong. That was one of the steps. Since ports from 1-1023 are privileged ports, and not allowed to be used by a non-root user/service, there was one option that needed to be changed. Thanks to the guys from the IRC I managed to enable this. File you need to edit is located at:
/etc/default/tomcat6
You open that file with some editor like nano or vim, and scroll to bottom and find the following line:
AUTHBIND=no
If it’s not there, then add it, and if it’s there it’s most likely commented so uncomment it and set the value to “yes” like this:
AUTHBIND=yes
That enables you to start the server on port 80. Second step is to locate the file:
/etc/tomcat6/server.xml
Find the following line:
<Connector port=”8080″ protocol=”HTTP/1.1″
Change 8080 into your desired port. Save the file and restart the server with the following command:
# /etc/init.d/tomcat6 restart
You don’t want two servers running on the same port so make sure apache2 or some other are stopped before running tomcat on this port. Apache and tomcat are started at boot so what you need to do is to remove one of them from startup. You can use the update-rc.d command on Debian. To remove apache2 from startup use it like this:
# update-rc.d apache2 remove
and to remove tomcat from the startup, type this:
# update-rc.d tomcat6 remove
Of course, you can run multiple HTTP servers at the same time, just make sure you run them on separate ports.
For manual starting or stopping the servers use init scripts in /etc/init.d.
Note1: If you want to run tomcat on ports higher that 1023 “AUTHBIND” option can be set to “no”.
Note2: “#” sign means that all commands must be run as root or at least as privileged user.
P.S. The folder for your web files is located at /var/lib/tomcat6/webapps/ROOT/
Of course this is just a fragment. Next thing you’ll need to do is configure virtual hosts and users. About that some other time.