Bitnami Apache Tomcat

NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.

Apache Tomcat is an open source application server which supports Java Servlets, JavaServer Pages and Java WebSockets.

How to change the Apache Tomcat port?

With the default configuration, Apache Tomcat will listen for requests on port 8080. To use a different port, edit the server.xml file and modify the value specified in the Port directive.

<Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" />

Restart the Apache Tomcat server for the changes to take effect.

How to configure the Apache Tomcat server?

The main Apache Tomcat configuration file is at installdir/apache-tomcat/conf/server.xml.

Once Apache Tomcat starts, it will create several log files in the installdir/apache-tomcat/logs directory. The main log file is the catalina.out file where you can find error messages.

How to change the Java memory settings?

The Java Virtual Machine (JVM) determines the default settings for your Java application:

JAVA_OPTS="-Xms256m -Xmx512m"

The Tomcat server uses CATALINA_OPTS to set these Java settings when running:

CATALINA_OPTS="-Xms256M -Xmx768M"

You can increase these settings if necessary by following the steps below:

Linux and Mac OS X

  • Modify the settings file installdir/apache-tomcat/bin/setenv.sh:

     $ export CATALINA_OPTS="$CATALINA_OPTS -Xms256M -Xmx768M"
    

    NOTE: You could also modify the Java Virtual Machine (JVM) settings if you prefer.

       $ export JAVA_OPTS="$JAVA_OPTS -Xms256M -Xmx768M"
    
  • Restart Tomcat after modifying the file:

     $ installdir/ctlscript.sh restart tomcat
    

Windows

  • Modify the settings file installdir/apache-tomcat/bin/setenv.bat:

     $ SET CATALINA_OPTS="%CATALINA_OPTS% -Xms256M -Xmx768M"
    

    NOTE: You could also modify the Java Virtual Machine (JVM) settings if you prefer.

       $ SET JAVA_OPTS="%JAVA_OPTS% -Xms256M -Xmx768M"
    
  • Reinstall the services after modifying the file, as shown below. Run the following commands from an elevated command prompt:

     $ cd installdir
     $ serviceinstall.bat UNINSTALL
     $ serviceinstall.bat INSTALL
    

How is Apache server connected with Tomcat?

Bitnami stacks include the Apache Web server. There are different ways to connect these two servers. One of them is connecting through the AJP protocol.

The AJP Connector element represents a Connector component that communicates with a web connector via the AJP protocol. This is used to invisibly integrate Tomcat into an Apache installation and have Apache handle the static content of the web application and/or to utilize Apache's SSL processing.

To make them work together, enable the mod_proxy.so and mod_proxy_ajp.so modules in installdir/apache2/conf/httpd.conf. Then, add the following lines to the file:

<Location /APPURL>
 ProxyPass ajp://localhost:8009/APPURL
</Location>

If you connect your application through AJP, you will probably want to disable the Tomcat HTTP port. The Bitnami Tomcat Stack has the HTTP server disabled by default. To modify this configuration, uncomment the HTTP section in the installdir/apache-tomcat/conf/server.xml file.

How to create a custom Java application?

Many users run a Bitnami stack as a development environment for their own projects (as opposed to running third-party applications). To create a custom Java application from scratch, follow the steps below. These steps assume that your application will live in the installdir/apps/myapp/ directory:

  • Run the following commands to create the directories:

    $ sudo mkdir installdir/apps/myapp
    $ sudo mkdir installdir/apps/myapp/conf
    
  • Create and edit the installdir/apps/myapp/conf/httpd-prefix.conf file and add the line below to it:

    Include "installdir/apps/myapp/conf/httpd-app.conf"
    
  • Create and edit the installdir/apps/myapp/conf/httpd-app.conf file and add the content below to it. This is the main configuration file for your application, so modify it further depending on your application's requirements.

    <Location /myapp>
    ProxyPass ajp://localhost:8009/myapp
    </Location>
    
    NOTE: 8009 is the default port for the AJP connector. If you have customized the stack to use a different port, change it here as well.
  • Once you have created the files and directories above, add the following line to the end of the main Apache configuration file at installdir/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:

    Include "installdir/apps/myapp/conf/httpd-prefix.conf"
    
  • Restart the Apache server.

You should now be able to access the application at http://localhost/myapp.

How to create an SSL certificate for Apache Tomcat?

A detailed guide is available in the official Apache Tomcat documentation at http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html.

How to debug errors in Tomcat?

The main Apache Tomcat configuration file is at installdir/apache-tomcat/conf/server.xml.

Once Apache Tomcat starts, it will create several log files in the installdir/apache-tomcat/logs directory. The main log file is the catalina.out file where you can find error messages. On some platforms, you may need root account privileges to view these files.

How to enable SSL access over HTTPS?

You can configure Apache Tomcat to enable SSL access to applications using HTTPS. It is necessary to configure Tomcat with the location of the Apache SSL certificate, as described below.

  • Check that the certificate file is present at installdir/apache-tomcat/conf/ssl/tomcat.cert.pem and the certificate key file is present at installdir/apache-tomcat/conf/ssl/tomcat.key.pem.

  • Uncomment the following line in the installdir/apache-tomcat/conf/server.xml file:

       <Connector port="8443"
                  protocol="HTTP/1.1" SSLEnabled="true"
                  maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                  enableLookups="false" disableUploadTimeout="true"
                  acceptCount="100" scheme="https" secure="true"
                  clientAuth="false" sslProtocol="TLS"
                  keystoreFile="conf/myKeystore"
                  keystorePass="your_password"
                  SSLCertificateFile="installdir/apache-tomcat/conf/ssl/tomcat.cert.pem"
                  SSLCertificateKeyFile="installdir/apache-tomcat/conf/ssl/tomcat.key.pem"/>
    
  • Restart the Apache Tomcat server

You should now be able to access your Web applications over HTTPS by browsing to https://localhost:8443.

How to increase the upload size limit in Tomcat?

Modify the max-file-size and max-request-size values in the application's web.xml configuration file (for example, in the webapps/manager/WEB-INF/web.xml file).

<max-file-size>83886080</max-file-size>
<max-request-size>83886080</max-request-size>

Remember to restart your Tomcat server for the changes to take effect.

How to install OracleDB client files for Apache Tomcat?

If you want your java application to be able to connect to a full featured and functional OracleDB database, please follow the steps below.

  • Stop the tomcat server:

     $ sudo installdir/ctlscript.sh stop tomcat
    
  • Download the corresponding JDBC drivers for OracleDB from the Oracle official website. Pay attention to the server version. For example, for a 11g Release 2 server, you will need OJDBC6.jar.

  • Unzip it and place it under the folder installdir/apache-tomcat/lib/ext

  • Start the tomcat server again:

     $ sudo installdir/ctlscript.sh start tomcat
    

That was it! Your tomcat installation can now connect to Oracle databases.

How to publish a Web page?

To serve Web pages with Apache Tomcat, simply copy your files to the default document root directory at installdir/apache-tomcat/webapps/ROOT.

NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.

How to use an independent Java installation instead of the bundled one?

Windows

Uninstall the Apache Tomcat service, edit the JAVA_HOME variable and then reinstall the Apache Tomcat service. For example, run the following commands from an elevated command prompt:

$ cd installdir\apache-tomcat\scripts
$ serviceinstall.bat UNINSTALL

Now change the JAVA_HOME variable in the installdir/apache-tomcat/bin/setenv.bat file to point to your custom Java installation. Then, reinstall the service as shown below from an elevated command prompt:

$ cd installdir\apache-tomcat\scripts
$ serviceinstall.bat INSTALL

Linux and Mac OS X

Change the JAVA_HOME variable in the installdir/apache-tomcat/bin/setenv.sh file and the JRE_HOME variable in the installdir/apache-tomcat/scripts/ctl.sh to point to your custom Java installation. Then, restart the Tomcat service:

$ installdir/ctlscript.sh restart tomcat
nativeInstaller

Bitnami Documentation