Configuring Stand-alone Apache Tomcat on Debian Linux Running as a Non-root User
This article describes how to install Apache Tomcat 5.5.20 Stand-alone on Debian Linux (Sarge) and run it as as a non-root user.
Install the Sun JDK
Download the self-extracting binary file for J2SE(TM) Development Kit 5.0 Update 9 from the following location to root’s home directory.
Make the file executable…
chmod +x jdk-1_5_0_09-linux-i586.bin
Change to your install directory…
cd /usr/lib
And execute the file…
~/jdk-1_5_0_09-linux-i586.bin
Accept the license agreement…
You will now have a directory named jdk1.5.0_09 in /usr/lib
Link it to /usr/lib/jdk for ease of use in future configuration tasks
ln -s jdk1.5.0_09 jdk
Add the java directory to the path…
vi /etc/profile
Add the following after the export PATH line…
export JAVA_HOME=”/usr/lib/jdk”
export JDK_HOME=”${JAVA_HOME}”
export PATH=”${JAVA_HOME}/bin:${PATH}”
Update your environment…
source /etc/profile
Test your install…
java -version
You should see something like…
java version “1.5.0_09″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b01)
Java HotSpot(TM) Client VM (build 1.5.0_09-b01, mixed mode, sharing)
Congratulations! JDK is now up and running!
Setup the Environment for Running as a Non-root User
Create a group…
groupadd tomcat
Create the user and enter a suitable password…
useradd -g tomcat tomcat
passwd tomcat
Install Apache Tomcat
Download Tomcat
wget http://apache.mirrors.tds.net/tomcat/tomcat-5/v5.5.20/bin/apache-tomcat-5.5.20.tar.gz
Unpack it…
tar xzvf apache-tomcat-5.5.20.tar.gz
move it to /usr/lib…
mv apache-tomcat-5.5.20 /usr/lib
Change the owner to tomcat…
chown -R tomcat:tomcat /usr/lib/apache-tomcat-5.5.20
Create a link for simplicity…
ln -s apache-tomcat-5.5.20 tomcat
Set the CATALINA_HOME environment variable…
vi /etc/profile
And add the following line after the “export PATH” line…
export CATALINA_HOME=”/usr/lib/tomcat”
And then update the environment…
source /etc/profile
Change server.xml so that tomcat listens on port 80
vi conf/server.xml
Change
Connector port=”8080″
To read
Connector port=”80″
Test the install as root…
cd /usr/lib/tomcat/bin
./startup/sh
You should see something like
Using CATALINA_BASE: /usr/lib/tomcat
Using CATALINA_HOME: /usr/lib/tomcat
Using CATALINA_TMPDIR: /usr/lib/tomcat/temp
Using JRE_HOME: /usr/lib/jdk
Open a Web browser and go to http://server to verify that the Apache default install page appears
If that looks good, stop tomcat
./shutdown.sh
Congratulations! Apache Tomcat is now up and running!
Complete the Non-root Configuration
Install autoconf in preparation for building jsvc…
apt-get install autoconf
Compile jsvc
cd $CATALINA_HOME/bin
tar xvfz jsvc.tar.gz
cd jsvc-src
autoconf
./configure
make
cp jsvc ..
cd ..
copy /usr/lib/tomcat/bin/jsvc-src/native/Tomcat5.sh /etc/init.d/tomcat
Edit Tomcat5.sh to look like this…
#!/bin/sh
JAVA_HOME=/usr/lib/jdk
CATALINA_HOME=/usr/lib/tomcat
DAEMON_HOME=/usr/lib/tomcat/bin
TOMCAT_USER=tomcat# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/usr/lib/tomcatCATALINA_OPTS=”"
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jarcase “$1″ in
start)
#
# Start Tomcat
#
$DAEMON_HOME/jsvc \
-user $TOMCAT_USER \
-home $JAVA_HOME \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
-wait 10 \
-pidfile $PID_FILE \
-outfile $CATALINA_HOME/logs/catalina.out \
-errfile ‘&1′ \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap
#
# To get a verbose JVM
#-verbose \
# To get a debug of jsvc.
#-debug \
exit $?
;;stop)
#
# Stop Tomcat
#
$DAEMON_HOME/jsvc \
-stop \
-pidfile $PID_FILE \
org.apache.catalina.startup.Bootstrap
exit $?
;;*)
echo “Usage tomcat.sh start/stop”
exit 1;;
esac
Configure init scripts…
update-rc.d tomcat defaults
And start up the service…
/etc/init.d/tomcat start
That should do it. Enjoy!