Deploy your Bitnami Tomcat Stack on Bitnami Cloud Hosting now! Launch Now

Tomcat for Bitnami Cloud Hosting

Description

Tomcat is a widely adopted open source Java application and web server. Created by the Apache Software Foundation, it is lightweight and agile with a large ecosystem of add-ons.

First steps with the Bitnami Tomcat Stack

Welcome to your new Bitnami application running on Bitnami Cloud Hosting! Here are a few questions (and answers!) you might need when first starting with your application.

What credentials do I need?

You need two sets of credentials:

  • The application credentials, consisting of a username and password. These credentials allow you to log in to your new Bitnami application.

  • The server credentials, consisting of an SSH username and key. These credentials allow you to log in to your Bitnami Cloud Hosting server using an SSH client and execute commands on the server using the command line.

What is the administrator username set for me to log in to the application for the first time?

Username: manager

What is the administrator password?

Click here for instructions.

What SSH username should I use for secure shell access to my application?

SSH username: bitnami

How do I get my SSH key or password?

You can obtain your SSH key from the Bitnami Cloud Hosting dashboard. Click here for more information.

What are the default ports?

A port is an endpoint of communication in an operating system that identifies a specific process or a type of service. Bitnami stacks include several services or servers that require a port.

Remember that if you need to open some ports you can follow the instructions given in the FAQ to learn how to open the server ports for remote access.

Port 22 is the default port for SSH connections.

Bitnami opens some ports for the main servers. These are the ports opened by default: 80, 443.

How can I get started with Tomcat?

To get started, we suggest the following steps:

Step 1. Publish Web pages.

To serve Web pages with Apache Tomcat, simply copy your files to the default document root directory at /opt/bitnami/apache-tomcat/webapps/ROOT. To deploy a WAR file, simply copy the WAR file to the /opt/bitnami/apache-tomcat/webapps folder.

Step 2. Access the management console.

Use the Tomcat management console to manage the Tomcat server and deploy applications. To access it, refer to these instructions.

Step 3. Use Apache with Tomcat.

You can connect the Apache Web server with Tomcat through the AJP protocol. To make them work together, enable the mod_proxy.so and mod_proxy_ajp.so modules in /opt/bitnami/apache2/conf/httpd.conf and then configure the ProxyPass directive .

For more information, refer to these instructions.

How to start or stop the services?

Each Bitnami stack includes a control script that lets you easily stop, start and restart services. The script is located at /opt/bitnami/ctlscript.sh. Call it without any service name arguments to start all services:

$ sudo /opt/bitnami/ctlscript.sh start

Or use it to restart a single service, such as Apache only, by passing the service name as argument:

$ sudo /opt/bitnami/ctlscript.sh restart apache

Use this script to stop all services:

$ sudo /opt/bitnami/ctlscript.sh stop

Restart the services by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh restart

Obtain a list of available services and operations by running the script without any arguments:

$ sudo /opt/bitnami/ctlscript.sh

How to access the Tomcat server console?

Access the Tomcat console by browsing to http://SERVER-IP/.

How to connect to Tomcat from a different machine?

For security reasons, Tomcat Manager and Tomcat Host Manager cannot be accessed over a public IP address. Both applications only work from localhost by default but you can allow remote connections by changing their configuration.

IMPORTANT: Make these applications accessible a public IP address is a significat security risk. Instead, use a secure channel such as a VPN or an SSH tunnel. Follow these instructions to remotely connect safely and reliably.

Connecting to Tomcat Manager from a different machine

In order to allow remote connections to the Tomcat Manager, follow the instructions below:

  • Create a file named /opt/bitnami/apache-tomcat/conf/Catalina/localhost/manager.xml with the following content:

    <Context privileged="true" antiResourceLocking="false" 
             docBase="${catalina.home}/webapps/manager">
        <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
    </Context>
    
  • Restart Tomcat:

    $ sudo /opt/bitnami/ctlscript.sh restart tomcat
    

Connecting to Tomcat Host Manager from a different machine

In order to allow remote connections to the Tomcat Host Manager, follow the instructions below:

  • Create a file named /opt/bitnami/apache-tomcat/conf/Catalina/localhost/host-manager.xml with the following content:

    <Context privileged="true" antiResourceLocking="false"
             docBase="${catalina.home}/webapps/host-manager">
        <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
    </Context>
    
  • Restart Tomcat:

    $ sudo /opt/bitnami/ctlscript.sh restart tomcat
    

How to upload files to the server with SFTP?

NOTE: Bitnami applications can be found in /opt/bitnami/apps.

First, obtain your SSH credentials by following these steps:

  • Browse to the Bitnami Cloud Hosting dashboard and sign in if required using your Bitnami account.

  • Select the "Servers" menu item.

  • Select your cloud server from the resulting list.

  • Click the "Manage" button.

  • On the resulting page, note the server IP address.

    SSH credentials

  • Click the "Connect" button and download the SSH key for your server in .ppk format (for FileZilla or WinSCP) or in .pem format (for Cyberduck).

    SSH credentials

Although you can use any SFTP/SCP client to transfer files to your server, this guide documents FileZilla (Windows, Linux and Mac OS X), WinSCP (Windows) and Cyberduck (Mac OS X).

Using an SSH Key

Once you have your server's SSH key, choose your preferred application and follow the steps below to connect to the server using SFTP.

FileZilla
IMPORTANT: To use FileZilla, your server private key should be in PPK format.

Follow these steps:

  • Download and install FileZilla.
  • Launch FileZilla and use the "Edit -> Settings" command to bring up FileZilla's configuration settings.
  • Within the "Connection -> SFTP" section, use the "Add keyfile" command to select the private key file for the server. FileZilla will use this private key to log in to the server.

    FileZilla configuration

  • Use the "File -> Site Manager -> New Site" command to bring up the FileZilla Site Manager, where you can set up a connection to your server.
  • Enter your server host name and specify bitnami as the user name.
  • Select "SFTP" as the protocol and "Ask for password" as the logon type.

    FileZilla configuration

  • Use the "Connect" button to connect to the server and begin an SFTP session. You might need to accept the server key, by clicking "Yes" or "OK" to proceed.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

If you have problems accessing your server, get extra information by use the "Edit -> Settings -> Debug" menu to activate FileZilla's debug log.

FileZilla debug log

WinSCP
IMPORTANT: To use WinSCP, your server private key should be in PPK format.

Follow these steps:

  • Download and install WinSCP.
  • Launch WinSCP and in the "Session" panel, select "SFTP" as the file protocol.
  • Enter your server host name and specify bitnami as the user name.

    WinSCP configuration

  • Click the "Advanced…" button and within the "SSH -> Authentication -> Authentication parameters" section, select the private key file for the server. WinSCP will use this private key to log in to the server.

    WinSCP configuration

  • From the "Session" panel, use the "Login" button to connect to the server and begin an SCP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

If you need to upload files to a location where the bitnami user doesn't have write permissions, you have two options:

  • Once you have configured WinSCP as described above, click the "Advanced…" button and within the "Environment -> Shell" panel, select sudo su - as your shell. This will allow you to upload files using the administrator account.

    WinSCP configuration

  • Upload the files to the /home/bitnami directory as usual. Then, connect via SSH and move the files to the desired location with the sudo command, as shown below:

     $ sudo mv /home/bitnami/uploaded-file /path/to/desired/location/
    
Cyberduck
IMPORTANT: To use Cyberduck, your server private key should be in PEM format.

Follow these steps:

  • Select the "Open Connection" command and specify "SFTP" as the connection protocol.

    Cyberduck configuration

  • In the connection details panel, under the "More Options" section, enable the "Use Public Key Authentication" option and specify the path to the private key file for the server.

    Cyberduck configuration

  • Use the "Connect" button to connect to the server and begin an SFTP session.

You should now be logged into the /home/bitnami directory on the server. You can now transfer files by dragging and dropping them from the local server window to the remote server window.

How to configure the Apache Tomcat server?

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

Once Apache Tomcat starts, it will create several log files in the /opt/bitnami/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"

You can increase these Java settings for your application if necessary. The settings are in the /opt/bitnami/java/bitnami/setenv.sh file. Here is an example of how to change the memory settings:

$ export JAVA_OPTS="$JAVA_OPTS -Xms256M -Xmx768M"
IMPORTANT: This file is a symlink to a configuration file that changes depending on the instance type that you are currently using. The symlink will be automatically changed when you resize your server.

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 publish a Web page?

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

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 /opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pem and the certificate key file is present at /opt/bitnami/apache-tomcat/conf/ssl/tomcat.key.pem.

  • Uncomment the following line in the /opt/bitnami/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="/opt/bitnami/apache-tomcat/conf/ssl/tomcat.cert.pem"
                  SSLCertificateKeyFile="/opt/bitnami/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://SERVER-IP:8443.

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 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 /opt/bitnami/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 /opt/bitnami/apache-tomcat/conf/server.xml file.

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 use an independent Java installation instead of the bundled one?

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

$ sudo /opt/bitnami/ctlscript.sh restart tomcat

How to debug errors in Tomcat?

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

Once Apache Tomcat starts, it will create several log files in the /opt/bitnami/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 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 /opt/bitnami/apps/myapp/ directory:

  • Run the following commands to create the directories:

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

    Include "/opt/bitnami/apps/myapp/conf/httpd-app.conf"
    
  • Create and edit the /opt/bitnami/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 /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf, as shown below:

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

You should now be able to access the application at http://SERVER-IP/myapp.

bch