     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: Java" href="https://sebthom.de/de/category/it/development/java-coding/feed/" />
     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: Linux" href="https://sebthom.de/de/category/it/linux/feed/" />
{"id":142,"date":"2010-03-13T17:07:35","date_gmt":"2010-03-13T16:07:35","guid":{"rendered":"http:\/\/sebthom.de\/?p=142"},"modified":"2012-12-18T19:52:50","modified_gmt":"2012-12-18T18:52:50","slug":"installing-tomcat-6-debian-squeeze","status":"publish","type":"post","link":"https:\/\/sebthom.de\/de\/142-installing-tomcat-6-debian-squeeze\/","title":{"rendered":"Installing Tomcat 6 on Debian Squeeze"},"content":{"rendered":"<p>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&#8217;s own webapp with context root \/ and optional support for PHP via the Quercus PHP implementation.<\/p>\n<h3>Installing Sun Java 6<\/h3>\n<p>Ensure the non-free section is enabled for the APT repository configuration in \/etc\/apt\/sources.list, e.g. &#8220;deb http:\/\/ftp.de.debian.org\/debian testing main contrib non-free&#8221;<\/p>\n<pre name=\"code\" class=\"php\">\r\napt-get update\r\napt-get install sun-java6-jdk\r\necho 'JAVA_HOME=\"\/usr\/lib\/jvm\/java-6-sun\"' >> \/etc\/environment\r\necho 'JRE_HOME=\"\/usr\/lib\/jvm\/java-6-sun\/jre\"' >> \/etc\/environment\r\n<\/pre>\n<h3>Installing Tomcat 6<\/h3>\n<pre  name=\"code\" class=\"php\">\r\napt-get install tomcat6 tomcat6-admin\r\n\/etc\/init.d\/tomcat6 stop\r\n<\/pre>\n<h3>Creating standard Tomcat directory layout (optional)<\/h3>\n<pre name=\"code\" class=\"php\">\r\nmkdir \/opt\/tomcat\r\ncd \/opt\/tomcat\r\nln -s \/etc\/tomcat6\/ conf\r\nln -s \/usr\/share\/tomcat6\/bin\/ bin\r\nln -s \/usr\/share\/tomcat6\/lib\/ lib\r\nln -s \/var\/lib\/tomcat6\/webapps webapps\r\nln -s \/var\/log\/tomcat6\/ logs\r\n<\/pre>\n<h3>Creating a Tomcat admin user<\/h3>\n<p>In \/opt\/tomcat\/conf\/tomcat-users.xml add an entry like:<\/p>\n<pre name=\"code\" class=\"xml\">\r\n&lt;user name=\"ADMIN_USERNAME\" password=\"ADMIN_PASSWORD\" roles=\"admin,manager\" \/&gt;\r\n<\/pre>\n<h3>Setting up virtual hosts<\/h3>\n<p>For each virtual host execute the following command. Replace &#8220;mydomain.com&#8221; with the desired virtual host name, but omit the &#8220;www.&#8221; part.<\/p>\n<pre name=\"code\" class=\"php\">\r\nmkdir -p \/opt\/tomcat\/webapps.mydomain.com\/ROOT\r\n<\/pre>\n<p>In the &lt;Engine&gt; tag of &#8220;\/opt\/tomcat\/conf\/server.xml&#8221; add one host entry for each virtual host.<\/p>\n<pre name=\"code\" class=\"xml\">\r\n&lt;Host name=\"mydomain.com\" appBase=\"\/opt\/tomcat\/webapps.mydomain.com\"&gt;\r\n    &lt;Alias&gt;www.mydomain.com&lt;\/Alias&gt;\r\n    &lt;Valve className=\"org.apache.catalina.valves.AccessLogValve\" prefix=\"mydomain_access_log.\" suffix=\".txt\" pattern=\"common\"\/&gt;\r\n&lt;\/Host&gt;\r\n<\/pre>\n<p>The &lt;Alias&gt; tag tells Tomcat to redirect from www.mydomain.com to mydomain.com.<br \/>\nThe &lt;Valve&gt; tag enables access logging in the standard logging format.<\/p>\n<h3>Using xinetd to configure port 80 for Tomcat<\/h3>\n<p>Binding a service on port 80 requires root permissions. Thus we use port forwarding to &#8220;bind&#8221; Tomcat to port 80. My VPS does not support the use of &#8220;iptables -j REDIRECT&#8221; therefore I am using xinetd as a web proxy.<br \/>\nEnsure that no other service is listening on port 80\/443:<\/p>\n<pre name=\"code\" class=\"php\">\r\nnetstat -pan | grep \":80\\|:443\"\r\n<\/pre>\n<p>Register the required xinetd services:<\/p>\n<pre name=\"code\" class=\"php\">\r\necho echo \"\r\nservice www\r\n{\r\n        socket_type     = stream\r\n        protocol        = tcp\r\n        user            = root\r\n        wait            = no\r\n        bind            = 88.80.198.181\r\n        port            = 80\r\n        redirect        = localhost 8080\r\n        disable         = no\r\n        flags           = REUSE\r\n        log_type        = FILE \/var\/log\/wwwaccess.log\r\n        log_on_success  -= PID HOST DURATION EXIT\r\n\r\n        per_source      = UNLIMITED\r\n        instances       = UNLIMITED\r\n}\r\n\r\nservice https\r\n{\r\n        socket_type     = stream\r\n        protocol        = tcp\r\n        user            = root\r\n        wait            = no\r\n        bind            = 88.80.198.181\r\n        port            = 443\r\n        redirect        = localhost 8443\r\n        disable         = no\r\n        flags           = REUSE\r\n        log_type        = FILE \/var\/log\/httpsaccess.log\r\n        log_on_success  -= PID HOST DURATION EXIT\r\n\r\n        per_source      = UNLIMITED\r\n        instances       = UNLIMITED\r\n}\r\n\" > \/etc\/xinetd.d\/tomcat\r\n\/etc\/init.d\/xinetd restart\r\n<\/pre>\n<p>If you want to use a different service name, e.g. &#8220;tomcat&#8221; instead of &#8220;www&#8221; you must add this service to \/var\/services, e.g. &#8220;tomcat 80\/tcp&#8221;<br \/>\nIn \/opt\/tomcat\/conf\/server.xml modify the &lt;Connector&gt; as follows:<\/p>\n<pre name=\"code\" class=\"xml\">\r\n&lt;Connector port=\"8080\" protocol=\"HTTP\/1.1\"\r\n               connectionTimeout=\"20000\"\r\n               redirectPort=\"8443\" proxyPort=\"80\" address=\"127.0.0.1\" \/&gt;\r\n<\/pre>\n<p>This binds Tomcat to localhost. It also tells Tomcat that port 80 is the proxy port which is necessary for correct URL generation.<br \/>\nFrom 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&#8217;s web browser. E.g. if you are using <a href=\"http:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/download.html\">PuTTY<\/a> you can use this command line option &#8220;-L 8080:localhost:8080&#8221; to forward the server&#8217;s local 8080 port to your workstation&#8217;s local 8080 port. On your workstation&#8217;s browser you then simply enter <a href=\"http:\/\/localhost:8080\/manager\/html\">http:\/\/localhost:8080\/manager\/html<\/a> and are connected to the server&#8217;s Tomcat admin application.<\/p>\n<h3>Enabling PHP support (optional)<\/h3>\n<p>Download <a href=\"http:\/\/quercus.caucho.com\/\">Quercus<\/a>.<\/p>\n<pre name=\"code\" class=\"php\">\r\nmkdir -p \/opt\/downloads\r\nwget -o \/opt\/downloads\/quercus-4.0.3.war http:\/\/caucho.com\/download\/quercus-4.0.3.war\r\n<\/pre>\n<p>Install Quercus as a shared library.<\/p>\n<pre name=\"code\" class=\"php\">\r\nunzip -j \/opt\/downloads\/quercus-4.0.3.war \\*.jar -d \/opt\/tomcat\/lib\r\n<\/pre>\n<p>Enable PHP support for the virtual hosts by installing the quercus web.xml. For each virtual host execute:<\/p>\n<pre name=\"code\" class=\"php\">\r\nunzip \/opt\/downloads\/quercus-4.0.3.war *web.xml -d \/opt\/tomcat\/webapps.mydomain.com\/ROOT\r\n<\/pre>\n<h3>Starting Tomcat<\/h3>\n<pre name=\"code\" class=\"php\">\r\n\/etc\/init.d\/tomcat start\r\n<\/pre>\n<h3>References<\/h3>\n<ul>\n<li><a href=\"http:\/\/www.ibm.com\/developerworks\/java\/library\/l-secjav.html#h5\">Securing Linux for Java services: The port dilemma<\/a>\n<li><a href=\"http:\/\/ruleoftech.com\/journal\/redirecting-http-and-https-traffic-to-tomcats-ports\">Redirect HTTP and HTTPS traffic to Tomcat&#8217;s ports<\/a>\n<li><a href=\"http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/virtual-hosting-howto.html\">Tomcat 6: Virtual Hosting How To<\/a>\n<li><a href=\"http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/class-loader-howto.html\">Tomcat 6: Classloader How To<\/a>\n<li><a href=\"http:\/\/www.ex-parrot.com\/pete\/tomcat-vhost.html\">Virtual Hosting with Tomcat<\/a>\n<li><a href=\"http:\/\/wiki.caucho.com\/Quercus:_Tomcat\">Quercus: Tomcat<\/a>\n<li><a href=\"http:\/\/www.ubuntugeek.com\/how-to-install-tomcat-6-on-ubuntu-9-04-jaunty.html\">How to install Tomcat 6 on Ubuntu 9.04 (Jaunty)<\/a>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s own webapp with context root \/ and&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,72],"tags":[30,16,84,83,80,79,81,85,86,82],"class_list":["post-142","post","type-post","status-publish","format-standard","hentry","category-java-coding","category-linux","tag-java","tag-php","tag-port-80","tag-port-forwarding","tag-quercus","tag-tomcat","tag-vhost","tag-virtual-servers","tag-vps","tag-xinetd"],"_links":{"self":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts\/142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/comments?post=142"}],"version-history":[{"count":0,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/posts\/142\/revisions"}],"wp:attachment":[{"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/media?parent=142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/categories?post=142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sebthom.de\/de\/wp-json\/wp\/v2\/tags?post=142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}