Installing Tomcat 7 on Debian/Ubuntu

First, a simple apt-get:

apt-get install tomcat7 libtcnative-1 tomcat7-user tomcat7-docs tomcat7-admin

Wait, “libtcnative-1”?
Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies. The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets). These features allows making Tomcat a general purpose webserver, will enable much better integration with other native web technologies, and overall make Java much more viable as a full fledged webserver platform rather than simply a backend focused technology. (

In /etc/tomcat7/server.xml

  • Uncomment the APR library loader:
 <!--APR library loader. Documentation at /docs/apr.html -->
   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  • Change the port of the connector for 80/443 and changes params:
 <Connector port="80" protocol="HTTP/1.1"
               redirectPort="443" maxKeepAliveRequests="1000" />

The maximum number of HTTP requests per TCP connection (maxKeepAliveRequests) defaults to 100 in Apache. In production, a higher value (e.g., 1,000) often provides better performance. A value of zero allows unlimited requests.

In /etc/default/tomcat7

  • Allow Tomcat to run on port numbers lower than 1023
  • Define correct JVM options and specify a heap dump path
JAVA_OPTS="-server -Xms4G -Xmx4G -XX:MaxPermSize=128m -XX:+DisableExplicitGC -XX:-HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tomcat7/dump -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseTLAB -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:MaxTenuringThreshold=0 -XX:SurvivorRatio=256 -XX:CMSInitiatingOccupancyFraction=60"

In /etc/tomcat7/web.xml
– Edit org.apache.jasper.servlet.JspServlet parameters:


Some explanations:

  • development: When using Jasper 2 in a production Tomcat server, set development to “false.” Set it to “true” in the development environment. One caveat: Sometimes this cannot be done, for example, with dynamic generation of JSPs.

  • genStringAsCharArray: set genStringAsCharArray to “true” to produce more efficient char arrays.

  • trimSpaces: set trimSpaces to “true” to remove useless bytes from the response.

In /etc/tomcat7/tomcat-users.xml

<role rolename="manager-gui"/>
<user username="a_user" password="a_password" roles="manager-gui"/>

Comments (4)

This helps me a ton, thank you very much. I noticed that the tomcat7 version is 7.0.28-4 on wheezy, and the host's undeployOldVersions is not yet supported. Is there any way i can update to the latest version of tomcat7 without sacrificing all the good stuffs from wheezy like the native libs (apr), authbind, logs, etc ?

Unfortunately, you can't without changing the Tomcat lib under the /lib directory. If you want the last version of a package under Debian 7, you can try to find a PPA, for instance

This comment has been removed by the author.

Hello again. Do you happen to know how to start multiple tomcat instances within a single debian wheezy box ? My production server went down badly yesterday, being unable to be connected although background threads are still running which can be seen from the logs. Tried stopping tomcat7 with invoke-rc.d tomcat7 stop, but that leaves a tomcat7 process. Had to restart the server. So i'm thinking to start multiple instances in case one instance goes down like this again.

Leave a comment

About privacy:

This site uses Akismet to reduce spam. Learn how your comment data is processed.