Skip to content

sebthom.de

Menu
  • Home
  • About me
  • Imprint
    • Datenschutzerklärung
  • Guestbook
Menu

Installing Tomcat 6 on Debian Squeeze

Posted on Saturday March 13th, 2010Tuesday December 18th, 2012 by sebthom

This post describes how to setup Tomcat 6 on Debian Squeeze. The configured Tomcat serves requests on port 80 without the need of an additional web server. This is especially good for virtual servers (VPS) providing limit memory. It also has multiple virtual hosts configured, each with it’s own webapp with context root / and optional support for PHP via the Quercus PHP implementation.

Installing Sun Java 6

Ensure the non-free section is enabled for the APT repository configuration in /etc/apt/sources.list, e.g. “deb //ftp.de.debian.org/debian testing main contrib non-free”

apt-get update
apt-get install sun-java6-jdk
echo 'JAVA_HOME="/usr/lib/jvm/java-6-sun"' >> /etc/environment
echo 'JRE_HOME="/usr/lib/jvm/java-6-sun/jre"' >> /etc/environment

Installing Tomcat 6

apt-get install tomcat6 tomcat6-admin
/etc/init.d/tomcat6 stop

Creating standard Tomcat directory layout (optional)

mkdir /opt/tomcat
cd /opt/tomcat
ln -s /etc/tomcat6/ conf
ln -s /usr/share/tomcat6/bin/ bin
ln -s /usr/share/tomcat6/lib/ lib
ln -s /var/lib/tomcat6/webapps webapps
ln -s /var/log/tomcat6/ logs

Creating a Tomcat admin user

In /opt/tomcat/conf/tomcat-users.xml add an entry like:

<user name="ADMIN_USERNAME" password="ADMIN_PASSWORD" roles="admin,manager" />

Setting up virtual hosts

For each virtual host execute the following command. Replace “mydomain.com” with the desired virtual host name, but omit the “www.” part.

mkdir -p /opt/tomcat/webapps.mydomain.com/ROOT

In the <Engine> tag of “/opt/tomcat/conf/server.xml” add one host entry for each virtual host.

<Host name="mydomain.com" appBase="/opt/tomcat/webapps.mydomain.com">
    <Alias>www.mydomain.com</Alias>
    <Valve className="org.apache.catalina.valves.AccessLogValve" prefix="mydomain_access_log." suffix=".txt" pattern="common"/>
</Host>

The <Alias> tag tells Tomcat to redirect from www.mydomain.com to mydomain.com.
The <Valve> tag enables access logging in the standard logging format.

Using xinetd to configure port 80 for Tomcat

Binding a service on port 80 requires root permissions. Thus we use port forwarding to “bind” Tomcat to port 80. My VPS does not support the use of “iptables -j REDIRECT” therefore I am using xinetd as a web proxy.
Ensure that no other service is listening on port 80/443:

netstat -pan | grep ":80\|:443"

Register the required xinetd services:

echo echo "
service www
{
        socket_type     = stream
        protocol        = tcp
        user            = root
        wait            = no
        bind            = 88.80.198.181
        port            = 80
        redirect        = localhost 8080
        disable         = no
        flags           = REUSE
        log_type        = FILE /var/log/wwwaccess.log
        log_on_success  -= PID HOST DURATION EXIT

        per_source      = UNLIMITED
        instances       = UNLIMITED
}

service https
{
        socket_type     = stream
        protocol        = tcp
        user            = root
        wait            = no
        bind            = 88.80.198.181
        port            = 443
        redirect        = localhost 8443
        disable         = no
        flags           = REUSE
        log_type        = FILE /var/log/httpsaccess.log
        log_on_success  -= PID HOST DURATION EXIT

        per_source      = UNLIMITED
        instances       = UNLIMITED
}
" > /etc/xinetd.d/tomcat
/etc/init.d/xinetd restart

If you want to use a different service name, e.g. “tomcat” instead of “www” you must add this service to /var/services, e.g. “tomcat 80/tcp”
In /opt/tomcat/conf/server.xml modify the <Connector> as follows:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" proxyPort="80" address="127.0.0.1" />

This binds Tomcat to localhost. It also tells Tomcat that port 80 is the proxy port which is necessary for correct URL generation.
From now on the Tomcat admin applications are only accessible via localhost. You can use SSH port forwarding to still access the applications from your workstation’s web browser. E.g. if you are using PuTTY you can use this command line option “-L 8080:localhost:8080” to forward the server’s local 8080 port to your workstation’s local 8080 port. On your workstation’s browser you then simply enter //localhost:8080/manager/html and are connected to the server’s Tomcat admin application.

Enabling PHP support (optional)

Download Quercus.

mkdir -p /opt/downloads
wget -o /opt/downloads/quercus-4.0.3.war //caucho.com/download/quercus-4.0.3.war

Install Quercus as a shared library.

unzip -j /opt/downloads/quercus-4.0.3.war \*.jar -d /opt/tomcat/lib

Enable PHP support for the virtual hosts by installing the quercus web.xml. For each virtual host execute:

unzip /opt/downloads/quercus-4.0.3.war *web.xml -d /opt/tomcat/webapps.mydomain.com/ROOT

Starting Tomcat

/etc/init.d/tomcat start

References

  • Securing Linux for Java services: The port dilemma
  • Redirect HTTP and HTTPS traffic to Tomcat’s ports
  • Tomcat 6: Virtual Hosting How To
  • Tomcat 6: Classloader How To
  • Virtual Hosting with Tomcat
  • Quercus: Tomcat
  • How to install Tomcat 6 on Ubuntu 9.04 (Jaunty)

10 thoughts on “Installing Tomcat 6 on Debian Squeeze”

  1. Pingback: Another setup of a geo-aware application server | geoaware
  2. Pingback: Apache Tomcat Kurulumu, Sanal Sunucu, 80 Portu | Anka BiliÅŸim Sistemleri
  3. Sprocket says:
    Thursday January 12th, 2012 at 01:01 PM

    I believe the xinetd service configuration file should be in /etc/xinetd.d, at least when using the standard Debian Squeeze install package for xinetd services. In this case line 37 should read
    ” > /etc/xinetd.d/tomcat

    Also, since you show https service it might be useful to mention that you need to set up a certificate keystone and https connector for tomcat.
    Otherwise, a great article and very helpful. Thanks for posting it.

  4. ggalante says:
    Thursday December 15th, 2011 at 05:00 PM

    Wouldn’t it be easier to simply use /var/lib/tomcat6 rather than creating the dir in /opt?

    It already has common, server, shared, and webapps, as well as links to conf, logs, and work. All you would need to do is create links to bin and lib.

  5. Web Hosting says:
    Friday December 9th, 2011 at 07:02 PM

    Nice one! I didn’t know it was possible to host PHP inside a Tomcat container. I’ll have to give that quercus thingy a try.

  6. George says:
    Monday November 28th, 2011 at 06:50 PM

    It should read:

    //www.mydomain.com

    (note the “>/Alias>” part in the original)

  7. Stefan says:
    Saturday November 26th, 2011 at 05:15 PM

    you flipped an > in the host-Tag. Thats bad for copying 😉

  8. Sergio says:
    Monday September 12th, 2011 at 12:39 PM

    Great blog .. i’m from Argentina and i have a blog too, can you tell me what plugin are you using to show codes ?
    Cause the one i use has lot of problems and i am looking a good one like your.
    Thanks 🙂

  9. Miikka Eloranta says:
    Wednesday June 1st, 2011 at 06:26 AM

    Did we put those service definitions to /etc/init.d/tomcat instead of /etc/init.d/tomcat6 by purpose?

  10. jean mendoza says:
    Tuesday April 5th, 2011 at 01:50 PM

    Hermano su aporte es demasiado beuno lo felicito, tengo una pregunta yaq que soy nuevo en esto, me gustaria saber como hago para correr un sistema con tomcat?? me explico mejor yo he venido trabajando con apache y se que para correr sistemas php solo debo colocarlos en /var/www y ejecutar //localhost/nombre_project ahora bien mi duda esta : en donde coloco los sistemas jsp o php que utilizen librerias java? para correrlos con tomcat??

    espero pronta respuesta , muchas gracias

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

  • Blog (1)
  • IT (21)
    • Development (16)
      • Java (7)
      • Jython (4)
      • Visual Basic (5)
    • Linux (3)
    • WebSphere Application Server (1)
    • WebSphere Portal (2)
    • Windows (1)
  • My Freeware (2)
  • My Music (3)

Recent Posts

  • Logging WebSphere API calls in wsadmin scripts
  • [Solved] Windows 7 “Safely Remove Hardware” pop-up menu horrendously slow
  • Bash: Capturing stderr in a variable while still printing to the console.
  • Configuring EMF Teneo with Hibernate, Commons DBCP, Spring Hibernate Transaction Manager, and the OpenSessionInViewFilter
  • Using EMF ECore model objects with Wicket components
  • Installing Tomcat 6 on Debian Squeeze
  • Leveraging PyDev’s auto-completion for indirectly created objects
  • OVal 1.40 released
  • Installing WebSphere Portal in a local network
  • Comparing version numbers in Jython / Python

Blogroll

  • E L S U A
  • elektrofever.de
  • OVal
  • Sweettt.com
  • Twins’ Running Blog

Recent Comments

  • Annibale on Visual Basic – Multiple Undos Class v2.04
  • Annibale on Visual Basic – Multiple Undos Class v2.04
  • koliko2k3 on Guestbook
  • hdkid on MyPad v1.1.6 – a PHP Editor
  • Luis Diego Villarreal on Excel – VBA Timer Example v1.0.1

Archives

  • June 2014
  • May 2012
  • January 2011
  • October 2010
  • September 2010
  • March 2010
  • February 2010
  • September 2009
  • July 2009
  • March 2009
  • February 2009
  • November 2008
  • September 2008
  • May 2008
  • September 2007
  • July 2007
  • July 2004
  • March 2003
  • August 2002
  • April 2002
  • January 2002
  • Deutsch (de)Deutsch
  • English (en)English
© 2025 sebthom.de | Powered by Minimalist Blog WordPress Theme